Skip to content

Commit 6fa941f

Browse files
committed
Wow, I made the tests pass
1 parent 9a50ac4 commit 6fa941f

File tree

8 files changed

+14
-11
lines changed

8 files changed

+14
-11
lines changed

agent/agent_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ func TestAgent(t *testing.T) {
465465

466466
conn, _ := setupAgent(t, codersdk.WorkspaceAgentMetadata{}, 0)
467467
require.Eventually(t, func() bool {
468-
_, err := conn.Ping()
468+
_, err := conn.Ping(context.Background())
469469
return err == nil
470470
}, testutil.WaitMedium, testutil.IntervalFast)
471471
conn1, err := conn.DialContext(context.Background(), l.Addr().Network(), l.Addr().String())

cli/agent_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestWorkspaceAgent(t *testing.T) {
6969
require.NoError(t, err)
7070
defer dialer.Close()
7171
require.Eventually(t, func() bool {
72-
_, err := dialer.Ping()
72+
_, err := dialer.Ping(ctx)
7373
return err == nil
7474
}, testutil.WaitMedium, testutil.IntervalFast)
7575
cancelFunc()
@@ -130,7 +130,7 @@ func TestWorkspaceAgent(t *testing.T) {
130130
require.NoError(t, err)
131131
defer dialer.Close()
132132
require.Eventually(t, func() bool {
133-
_, err := dialer.Ping()
133+
_, err := dialer.Ping(ctx)
134134
return err == nil
135135
}, testutil.WaitMedium, testutil.IntervalFast)
136136
cancelFunc()
@@ -191,7 +191,7 @@ func TestWorkspaceAgent(t *testing.T) {
191191
require.NoError(t, err)
192192
defer dialer.Close()
193193
require.Eventually(t, func() bool {
194-
_, err := dialer.Ping()
194+
_, err := dialer.Ping(ctx)
195195
return err == nil
196196
}, testutil.WaitMedium, testutil.IntervalFast)
197197
cancelFunc()

cli/portforward.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func portForward() *cobra.Command {
155155
case <-ticker.C:
156156
}
157157

158-
_, err = conn.Ping()
158+
_, err = conn.Ping(ctx)
159159
if err != nil {
160160
continue
161161
}

cli/speedtest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func speedtest() *cobra.Command {
7070
return ctx.Err()
7171
case <-ticker.C:
7272
}
73-
dur, err := conn.Ping()
73+
dur, err := conn.Ping(ctx)
7474
if err != nil {
7575
continue
7676
}

coderd/workspaceagents_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func TestWorkspaceAgentListen(t *testing.T) {
129129
_ = conn.Close()
130130
}()
131131
require.Eventually(t, func() bool {
132-
_, err := conn.Ping()
132+
_, err := conn.Ping(ctx)
133133
return err == nil
134134
}, testutil.WaitLong, testutil.IntervalFast)
135135
})

codersdk/agentconn.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ type AgentConn struct {
132132
CloseFunc func()
133133
}
134134

135-
func (c *AgentConn) Ping() (time.Duration, error) {
135+
func (c *AgentConn) Ping(ctx context.Context) (time.Duration, error) {
136136
errCh := make(chan error, 1)
137137
durCh := make(chan time.Duration, 1)
138138
c.Conn.Ping(TailnetIP, tailcfg.PingDisco, func(pr *ipnstate.PingResult) {
@@ -145,6 +145,8 @@ func (c *AgentConn) Ping() (time.Duration, error) {
145145
select {
146146
case err := <-errCh:
147147
return 0, err
148+
case <-ctx.Done():
149+
return 0, ctx.Err()
148150
case dur := <-durCh:
149151
return dur, nil
150152
}

enterprise/coderd/coderd.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package coderd
33
import (
44
"context"
55
"crypto/ed25519"
6-
"fmt"
76
"net/http"
87
"sync"
98
"time"
@@ -247,7 +246,6 @@ func (api *API) updateEntitlements(ctx context.Context) error {
247246
coordinator = haCoordinator
248247
}
249248

250-
fmt.Printf("HA enabled\n")
251249
api.replicaManager.SetCallback(func() {
252250
addresses := make([]string, 0)
253251
for _, replica := range api.replicaManager.Regional() {

enterprise/coderd/replicas_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package coderd_test
33
import (
44
"context"
55
"testing"
6+
"time"
67

78
"github.com/stretchr/testify/require"
89

@@ -69,7 +70,9 @@ func TestReplicas(t *testing.T) {
6970
})
7071
require.NoError(t, err)
7172
require.Eventually(t, func() bool {
72-
_, err = conn.Ping()
73+
ctx, cancelFunc := context.WithTimeout(context.Background(), 3*time.Second)
74+
defer cancelFunc()
75+
_, err = conn.Ping(ctx)
7376
return err == nil
7477
}, testutil.WaitLong, testutil.IntervalFast)
7578
_ = conn.Close()

0 commit comments

Comments
 (0)