- Notifications
You must be signed in to change notification settings - Fork1k
chore: add Now, Since, AfterFunc to clock; use clock for configmaps test#13476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -7,7 +7,6 @@ import ( | ||
"testing" | ||
"time" | ||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
@@ -22,6 +21,7 @@ import ( | ||
"cdr.dev/slog" | ||
"cdr.dev/slog/sloggers/slogtest" | ||
"github.com/coder/coder/v2/clock" | ||
"github.com/coder/coder/v2/tailnet/proto" | ||
"github.com/coder/coder/v2/testutil" | ||
) | ||
@@ -195,9 +195,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_neverConfigures(t *testing. | ||
discoKey := key.NewDisco() | ||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public()) | ||
defer uut.close() | ||
mClock := clock.NewMock() | ||
uut.clock = mClock | ||
p1ID := uuid.UUID{1} | ||
@@ -241,9 +239,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_outOfOrder(t *testing.T) { | ||
discoKey := key.NewDisco() | ||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public()) | ||
defer uut.close() | ||
mClock := clock.NewMock() | ||
uut.clock = mClock | ||
p1ID := uuid.UUID{1} | ||
@@ -314,9 +310,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake(t *testing.T) { | ||
discoKey := key.NewDisco() | ||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public()) | ||
defer uut.close() | ||
mClock := clock.NewMock() | ||
uut.clock = mClock | ||
p1ID := uuid.UUID{1} | ||
@@ -387,9 +381,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_timeout(t *testing.T) { | ||
discoKey := key.NewDisco() | ||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public()) | ||
defer uut.close() | ||
mClock := clock.NewMock() | ||
uut.clock = mClock | ||
p1ID := uuid.UUID{1} | ||
@@ -412,7 +404,7 @@ func TestConfigMaps_updatePeers_new_waitForHandshake_timeout(t *testing.T) { | ||
} | ||
uut.updatePeers(u1) | ||
mClock.Advance(5*time.Second).MustWait(ctx, t) | ||
// it should now send the peer to the netmap | ||
@@ -574,9 +566,8 @@ func TestConfigMaps_updatePeers_lost(t *testing.T) { | ||
discoKey := key.NewDisco() | ||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public()) | ||
defer uut.close() | ||
mClock := clock.NewMock() | ||
start :=mClock.Now() | ||
uut.clock = mClock | ||
p1ID := uuid.UUID{1} | ||
@@ -600,7 +591,7 @@ func TestConfigMaps_updatePeers_lost(t *testing.T) { | ||
require.Len(t, r.wg.Peers, 1) | ||
_ = testutil.RequireRecvCtx(ctx, t, s1) | ||
mClock.Advance(5*time.Second).MustWait(ctx, t) | ||
s2 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, start) | ||
@@ -621,7 +612,7 @@ func TestConfigMaps_updatePeers_lost(t *testing.T) { | ||
// latest handshake has advanced by a minute, so we don't remove the peer. | ||
lh := start.Add(time.Minute) | ||
s3 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, lh) | ||
mClock.Advance(lostTimeout).MustWait(ctx, t) | ||
_ = testutil.RequireRecvCtx(ctx, t, s3) | ||
select { | ||
case <-fEng.setNetworkMap: | ||
@@ -630,18 +621,10 @@ func TestConfigMaps_updatePeers_lost(t *testing.T) { | ||
// OK! | ||
} | ||
Comment on lines -633 to -639 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Why do we no longer need this check? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm glad you asked! One of the benefits of this library compared with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Nice! | ||
// Advance the clock again by a minute, which should trigger the reprogrammed | ||
// timeout. | ||
s4 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, lh) | ||
mClock.Advance(time.Minute).MustWait(ctx, t) | ||
nm = testutil.RequireRecvCtx(ctx, t, fEng.setNetworkMap) | ||
r = testutil.RequireRecvCtx(ctx, t, fEng.reconfig) | ||
@@ -667,9 +650,8 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) { | ||
discoKey := key.NewDisco() | ||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public()) | ||
defer uut.close() | ||
mClock := clock.NewMock() | ||
start :=mClock.Now() | ||
uut.clock = mClock | ||
p1ID := uuid.UUID{1} | ||
@@ -693,7 +675,7 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) { | ||
require.Len(t, r.wg.Peers, 1) | ||
_ = testutil.RequireRecvCtx(ctx, t, s1) | ||
mClock.Advance(5*time.Second).MustWait(ctx, t) | ||
s2 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, start) | ||
@@ -710,7 +692,7 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) { | ||
// OK! | ||
} | ||
mClock.Advance(5*time.Second).MustWait(ctx, t) | ||
s3 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, start) | ||
updates[0].Kind = proto.CoordinateResponse_PeerUpdate_NODE | ||
@@ -727,7 +709,7 @@ func TestConfigMaps_updatePeers_lost_and_found(t *testing.T) { | ||
// When we advance the clock, nothing happens because the timeout was | ||
// canceled | ||
mClock.Advance(lostTimeout).MustWait(ctx, t) | ||
select { | ||
case <-fEng.setNetworkMap: | ||
t.Fatal("should not reprogram") | ||
@@ -753,9 +735,8 @@ func TestConfigMaps_setAllPeersLost(t *testing.T) { | ||
discoKey := key.NewDisco() | ||
uut := newConfigMaps(logger, fEng, nodeID, nodePrivateKey, discoKey.Public()) | ||
defer uut.close() | ||
mClock := clock.NewMock() | ||
start :=mClock.Now() | ||
uut.clock = mClock | ||
p1ID := uuid.UUID{1} | ||
@@ -788,7 +769,7 @@ func TestConfigMaps_setAllPeersLost(t *testing.T) { | ||
require.Len(t, r.wg.Peers, 2) | ||
_ = testutil.RequireRecvCtx(ctx, t, s1) | ||
mClock.Advance(5*time.Second).MustWait(ctx, t) | ||
uut.setAllPeersLost() | ||
// No reprogramming yet, since we keep the peer around. | ||
@@ -802,7 +783,7 @@ func TestConfigMaps_setAllPeersLost(t *testing.T) { | ||
// When we advance the clock, even by a few ms, the timeout for peer 2 pops | ||
// because our status only includes a handshake for peer 1 | ||
s2 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, start) | ||
mClock.Advance(time.Millisecond*10).MustWait(ctx, t) | ||
_ = testutil.RequireRecvCtx(ctx, t, s2) | ||
nm = testutil.RequireRecvCtx(ctx, t, fEng.setNetworkMap) | ||
@@ -812,7 +793,7 @@ func TestConfigMaps_setAllPeersLost(t *testing.T) { | ||
// Finally, advance the clock until after the timeout | ||
s3 := expectStatusWithHandshake(ctx, t, fEng, p1Node.Key, start) | ||
mClock.Advance(lostTimeout).MustWait(ctx, t) | ||
_ = testutil.RequireRecvCtx(ctx, t, s3) | ||
nm = testutil.RequireRecvCtx(ctx, t, fEng.setNetworkMap) | ||