Skip to content

Commit 6e0d726

Browse files
Fix flaky auth tests (#92)
1 parent 7b740b4 commit 6e0d726

2 files changed

Lines changed: 1 addition & 22 deletions

File tree

internal/tiger/cmd/auth_test.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"regexp"
1616
"strings"
1717
"testing"
18-
"time"
1918

2019
"github.com/timescale/tiger-cli/internal/tiger/config"
2120
)
@@ -410,10 +409,6 @@ func mockOpenBrowser(t *testing.T) func(string) error {
410409

411410
// Give the OAuth server a moment to start
412411
go func() {
413-
// Sleep to ensure the OAuth callback server is listening
414-
// This prevents "EOF" errors in CI when the server hasn't started yet
415-
time.Sleep(100 * time.Millisecond)
416-
417412
// Make the OAuth callback request directly
418413
callbackURL := fmt.Sprintf("%s?code=test-auth-code&state=%s", redirectURI, state)
419414
t.Logf("Mock browser making callback request to: %s", callbackURL)

internal/tiger/cmd/oauth.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (l *oauthLogin) getAccessToken(ctx context.Context) (string, error) {
7777
return "", fmt.Errorf("failed to create local server: %w", err)
7878
}
7979
defer func() {
80-
if err := server.Close(); err != nil {
80+
if err := server.server.Shutdown(ctx); err != nil {
8181
fmt.Fprintf(l.out, "Failed to close local server: %s\n", err)
8282
}
8383
}()
@@ -110,7 +110,6 @@ func (l *oauthLogin) generateRandomState(length int) (string, error) {
110110
}
111111

112112
type oauthServer struct {
113-
listener net.Listener
114113
server *http.Server
115114
oauthCfg oauth2.Config
116115
resultChan <-chan oauthResult
@@ -162,26 +161,11 @@ func (l *oauthLogin) startOAuthServer(expectedState, codeVerifier string) (*oaut
162161

163162
return &oauthServer{
164163
server: server,
165-
listener: listener,
166164
oauthCfg: oauthCfg,
167165
resultChan: resultChan,
168166
}, nil
169167
}
170168

171-
func (s *oauthServer) Close() error {
172-
cls := func(closer io.Closer) error {
173-
if err := closer.Close(); err != nil && !errors.Is(err, net.ErrClosed) {
174-
return err
175-
}
176-
return nil
177-
}
178-
179-
return errors.Join(
180-
cls(s.server),
181-
cls(s.listener),
182-
)
183-
}
184-
185169
type oauthCallback struct {
186170
oauthCfg oauth2.Config
187171
expectedState string

0 commit comments

Comments
 (0)