Browse Source

SetMockTime() for cleaner unit testing

pull/1/head
Gavin Andresen 11 years ago
parent
commit
54d02f158d
  1. 9
      src/util.cpp
  2. 1
      src/util.h

9
src/util.cpp

@ -815,11 +815,20 @@ void ShrinkDebugFile() @@ -815,11 +815,20 @@ void ShrinkDebugFile()
// - Median of other nodes's clocks
// - The user (asking the user to fix the system clock if the first two disagree)
//
static int64 nMockTime = 0; // For unit testing
int64 GetTime()
{
if (nMockTime) return nMockTime;
return time(NULL);
}
void SetMockTime(int64 nMockTimeIn)
{
nMockTime = nMockTimeIn;
}
static int64 nTimeOffset = 0;
int64 GetAdjustedTime()

1
src/util.h

@ -199,6 +199,7 @@ void ShrinkDebugFile(); @@ -199,6 +199,7 @@ void ShrinkDebugFile();
int GetRandInt(int nMax);
uint64 GetRand(uint64 nMax);
int64 GetTime();
void SetMockTime(int64 nMockTimeIn);
int64 GetAdjustedTime();
void AddTimeData(unsigned int ip, int64 nTime);
std::string FormatFullVersion();

Loading…
Cancel
Save