@@ -46,7 +46,7 @@ func TestBatchStats(t *testing.T) {
46
46
47
47
// Given: no data points are added for workspace
48
48
// When: it becomes time to report stats
49
- t1 := time .Now ()
49
+ t1 := database .Now ()
50
50
// Signal a tick and wait for a flush to complete.
51
51
tick <- t1
52
52
f := <- flushed
@@ -59,9 +59,9 @@ func TestBatchStats(t *testing.T) {
59
59
require .Empty (t , stats , "should have no stats for workspace" )
60
60
61
61
// Given: a single data point is added for workspace
62
- t2 := time . Now ( )
62
+ t2 := t1 . Add ( time . Second )
63
63
t .Logf ("inserting 1 stat" )
64
- require .NoError (t , b .Add (deps1 .Agent .ID , deps1 .User .ID , deps1 .Template .ID , deps1 .Workspace .ID , randAgentSDKStats (t )))
64
+ require .NoError (t , b .Add (t2 . Add ( time . Millisecond ), deps1 .Agent .ID , deps1 .User .ID , deps1 .Template .ID , deps1 .Workspace .ID , randAgentSDKStats (t )))
65
65
66
66
// When: it becomes time to report stats
67
67
// Signal a tick and wait for a flush to complete.
@@ -77,17 +77,17 @@ func TestBatchStats(t *testing.T) {
77
77
78
78
// Given: a lot of data points are added for both workspaces
79
79
// (equal to batch size)
80
- t3 := time . Now ( )
80
+ t3 := t2 . Add ( time . Second )
81
81
done := make (chan struct {})
82
82
83
83
go func () {
84
84
defer close (done )
85
85
t .Logf ("inserting %d stats" , defaultBufferSize )
86
86
for i := 0 ; i < defaultBufferSize ; i ++ {
87
87
if i % 2 == 0 {
88
- require .NoError (t , b .Add (deps1 .Agent .ID , deps1 .User .ID , deps1 .Template .ID , deps1 .Workspace .ID , randAgentSDKStats (t )))
88
+ require .NoError (t , b .Add (t3 . Add ( time . Millisecond ), deps1 .Agent .ID , deps1 .User .ID , deps1 .Template .ID , deps1 .Workspace .ID , randAgentSDKStats (t )))
89
89
} else {
90
- require .NoError (t , b .Add (deps2 .Agent .ID , deps2 .User .ID , deps2 .Template .ID , deps2 .Workspace .ID , randAgentSDKStats (t )))
90
+ require .NoError (t , b .Add (t3 . Add ( time . Millisecond ), deps2 .Agent .ID , deps2 .User .ID , deps2 .Template .ID , deps2 .Workspace .ID , randAgentSDKStats (t )))
91
91
}
92
92
}
93
93
}()
@@ -105,15 +105,15 @@ func TestBatchStats(t *testing.T) {
105
105
require .Len (t , stats , 2 , "should have stats for both workspaces" )
106
106
107
107
// Ensures that a subsequent flush pushes all the remaining data
108
- t4 := time . Now ( )
108
+ t4 := t3 . Add ( time . Second )
109
109
tick <- t4
110
110
f2 := <- flushed
111
111
t .Logf ("flush 4 completed" )
112
112
expectedCount := defaultBufferSize - f
113
113
require .Equal (t , expectedCount , f2 , "did not flush expected remaining rows" )
114
114
115
115
// Ensure that a subsequent flush does not push stale data.
116
- t5 := time . Now ( )
116
+ t5 := t4 . Add ( time . Second )
117
117
tick <- t5
118
118
f = <- flushed
119
119
require .Zero (t , f , "expected zero stats to have been flushed" )
0 commit comments