Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6238065

Browse files
authored
test: use not before in TestAgentConnectionMonitor_* (#21332)
fixescoder/internal#1203The matcher I wrote for TestAgentConnectionMonitor tested that `last_disconnected_at` was strictly _after_ the start of the test to ensure it was updated.This is too strict of a test because Windows in particular doesn't have high-resolution timers, so it's entirely possible to get the exact same timestamp from subsequent calls to `time.Now()`. This PR switches the test to _not before_ to cover this case. The results are just as valid because we always initialize the `last_disconnected_at` to something well before the test starts.
1 parent81cbf03 commit6238065

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

‎coderd/workspaceagentsrpc_internal_test.go‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func TestAgentConnectionMonitor_ContextCancel(t *testing.T) {
9494
Return(nil)
9595
mDB.EXPECT().UpdateWorkspaceAgentConnectionByID(
9696
gomock.Any(),
97-
connectionUpdate(agentID,replicaID,withDisconnectedAfter(now)),
97+
connectionUpdate(agentID,replicaID,withDisconnectedNotBefore(now)),
9898
).
9999
After(connected).
100100
Times(1).
@@ -172,7 +172,7 @@ func TestAgentConnectionMonitor_PingTimeout(t *testing.T) {
172172
Return(nil)
173173
mDB.EXPECT().UpdateWorkspaceAgentConnectionByID(
174174
gomock.Any(),
175-
connectionUpdate(agent.ID,replicaID,withDisconnectedAfter(now)),
175+
connectionUpdate(agent.ID,replicaID,withDisconnectedNotBefore(now)),
176176
).
177177
After(connected).
178178
Times(1).
@@ -235,7 +235,7 @@ func TestAgentConnectionMonitor_BuildOutdated(t *testing.T) {
235235
Return(nil)
236236
mDB.EXPECT().UpdateWorkspaceAgentConnectionByID(
237237
gomock.Any(),
238-
connectionUpdate(agent.ID,replicaID,withDisconnectedAfter(now)),
238+
connectionUpdate(agent.ID,replicaID,withDisconnectedNotBefore(now)),
239239
).
240240
After(connected).
241241
Times(1).
@@ -320,7 +320,7 @@ func TestAgentConnectionMonitor_StartClose(t *testing.T) {
320320
Return(nil)
321321
mDB.EXPECT().UpdateWorkspaceAgentConnectionByID(
322322
gomock.Any(),
323-
connectionUpdate(agent.ID,replicaID,withDisconnectedAfter(now)),
323+
connectionUpdate(agent.ID,replicaID,withDisconnectedNotBefore(now)),
324324
).
325325
After(connected).
326326
Times(1).
@@ -423,10 +423,10 @@ func (f *fakeUpdater) getUpdates() int {
423423
}
424424

425425
typeconnectionUpdateMatcherstruct {
426-
agentID uuid.UUID
427-
replicaID uuid.UUID
428-
disconnectedAt sql.NullTime
429-
disconnectedAfter sql.NullTime
426+
agentIDuuid.UUID
427+
replicaIDuuid.UUID
428+
disconnectedAtsql.NullTime
429+
disconnectedNotBefore sql.NullTime
430430
}
431431

432432
typeconnectionUpdateMatcherOptionfunc(mconnectionUpdateMatcher)connectionUpdateMatcher
@@ -442,9 +442,9 @@ func connectionUpdate(id, replica uuid.UUID, opts ...connectionUpdateMatcherOpti
442442
returnm
443443
}
444444

445-
funcwithDisconnectedAfter(t time.Time)connectionUpdateMatcherOption {
445+
funcwithDisconnectedNotBefore(t time.Time)connectionUpdateMatcherOption {
446446
returnfunc(mconnectionUpdateMatcher)connectionUpdateMatcher {
447-
m.disconnectedAfter= sql.NullTime{
447+
m.disconnectedNotBefore= sql.NullTime{
448448
Valid:true,
449449
Time:t,
450450
}
@@ -476,23 +476,23 @@ func (m connectionUpdateMatcher) Matches(x interface{}) bool {
476476
ifargs.LastConnectedReplicaID.UUID!=m.replicaID {
477477
returnfalse
478478
}
479-
ifm.disconnectedAfter.Valid {
479+
ifm.disconnectedNotBefore.Valid {
480480
if!args.DisconnectedAt.Valid {
481481
returnfalse
482482
}
483-
if!args.DisconnectedAt.Time.After(m.disconnectedAfter.Time) {
483+
ifargs.DisconnectedAt.Time.Before(m.disconnectedNotBefore.Time) {
484484
returnfalse
485485
}
486-
//disconnectedAfter takes precedence over disconnectedAt
486+
//disconnectedNotBefore takes precedence over disconnectedAt
487487
}elseifargs.DisconnectedAt!=m.disconnectedAt {
488488
returnfalse
489489
}
490490
returntrue
491491
}
492492

493493
func (mconnectionUpdateMatcher)String()string {
494-
returnfmt.Sprintf("{agent=%s, replica=%s, disconnectedAt=%v,disconnectedAfter=%v}",
495-
m.agentID.String(),m.replicaID.String(),m.disconnectedAt,m.disconnectedAfter)
494+
returnfmt.Sprintf("{agent=%s, replica=%s, disconnectedAt=%v,disconnectedNotBefore=%v}",
495+
m.agentID.String(),m.replicaID.String(),m.disconnectedAt,m.disconnectedNotBefore)
496496
}
497497

498498
func (connectionUpdateMatcher)Got(xinterface{})string {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp