Skip to content

Commit 2553993

Browse files
committed
remove race from test
1 parent 0f283ca commit 2553993

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

.github/workflows/go-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
go-version: "1.24"
2424
cache-dependency-path: go/go.sum
2525

26+
# Runs test with shuffle and count to expose flaky tests.
2627
- name: Run tests
2728
working-directory: go
28-
run: go test -race ./...
29+
run: go test -count=10 -shuffle=on ./...

go/stream.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,13 @@ func (c *client) newStream(ctx context.Context, httpClient *http.Client, feedIDs
136136
if err != nil {
137137
return
138138
}
139-
s.addConn(conn)
139+
go s.monitorConn(conn)
140+
s.conns = append(s.conns, conn)
140141
}()
141142
continue
142143
}
143-
s.addConn(conn)
144+
go s.monitorConn(conn)
145+
s.conns = append(s.conns, conn)
144146
}
145147

146148
// Only fail if we couldn't connect to ANY origins
@@ -164,16 +166,6 @@ func (c *client) newStream(ctx context.Context, httpClient *http.Client, feedIDs
164166
return s, nil
165167
}
166168

167-
// addConn adds a connection to the monitoring goroutine aquires the closingMutex to append the connection
168-
// to the stream's connection list safely. It uses the closingMutex to prevent a race conditions with Close()
169-
// but is also using this mutex to prevent race conditions with other goroutines appending to conns.
170-
func (s *stream) addConn(conn *wsConn) {
171-
go s.monitorConn(conn)
172-
s.closingMutex.Lock()
173-
s.conns = append(s.conns, conn)
174-
s.closingMutex.Unlock()
175-
}
176-
177169
func (s *stream) pingConn(ctx context.Context, conn *wsConn) {
178170
ticker := time.NewTicker(time.Second * 2)
179171
defer ticker.Stop()

0 commit comments

Comments
 (0)