File tree Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Expand file tree Collapse file tree 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -2952,9 +2952,12 @@ func TestAgent_Reconnect(t *testing.T) {
2952
2952
defer closer .Close ()
2953
2953
2954
2954
call1 := testutil .RequireReceive (ctx , t , fCoordinator .CoordinateCalls )
2955
+ require .Equal (t , client .GetNumRefreshTokenCalls (), 1 )
2955
2956
close (call1 .Resps ) // hang up
2956
2957
// expect reconnect
2957
2958
testutil .RequireReceive (ctx , t , fCoordinator .CoordinateCalls )
2959
+ // Check that the agent refreshes the token when it reconnects.
2960
+ require .Equal (t , client .GetNumRefreshTokenCalls (), 2 )
2958
2961
closer .Close ()
2959
2962
}
2960
2963
Original file line number Diff line number Diff line change @@ -88,10 +88,11 @@ type Client struct {
88
88
fakeAgentAPI * FakeAgentAPI
89
89
LastWorkspaceAgent func ()
90
90
91
- mu sync.Mutex // Protects following.
92
- logs []agentsdk.Log
93
- derpMapUpdates chan * tailcfg.DERPMap
94
- derpMapOnce sync.Once
91
+ mu sync.Mutex // Protects following.
92
+ logs []agentsdk.Log
93
+ derpMapUpdates chan * tailcfg.DERPMap
94
+ derpMapOnce sync.Once
95
+ refreshTokenCalls int
95
96
}
96
97
97
98
func (* Client ) AsRequestOption () codersdk.RequestOption {
@@ -104,10 +105,19 @@ func (*Client) GetSessionToken() string {
104
105
return "agenttest-token"
105
106
}
106
107
107
- func (* Client ) RefreshToken (context.Context ) error {
108
+ func (c * Client ) RefreshToken (context.Context ) error {
109
+ c .mu .Lock ()
110
+ defer c .mu .Unlock ()
111
+ c .refreshTokenCalls ++
108
112
return nil
109
113
}
110
114
115
+ func (c * Client ) GetNumRefreshTokenCalls () int {
116
+ c .mu .Lock ()
117
+ defer c .mu .Unlock ()
118
+ return c .refreshTokenCalls
119
+ }
120
+
111
121
func (* Client ) RewriteDERPMap (* tailcfg.DERPMap ) {}
112
122
113
123
func (c * Client ) Close () {
You can’t perform that action at this time.
0 commit comments