Skip to content

Commit

Permalink
fixing race condition on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Dec 18, 2024
1 parent e0d13fe commit 90c16b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions api/subscriptions/pending_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,9 @@ func TestPendingTx_UnsubscribeOnWebSocketClose(t *testing.T) {

// Wait to receive transaction
time.Sleep(500 * time.Millisecond)
sub.pendingTx.mu.Lock()
require.Equal(t, len(sub.pendingTx.listeners), 1)
sub.pendingTx.mu.Unlock()

// Simulate WebSocket closure
ws.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
Expand All @@ -236,5 +238,7 @@ func TestPendingTx_UnsubscribeOnWebSocketClose(t *testing.T) {
time.Sleep(5 * time.Second)

// Assert cleanup
sub.pendingTx.mu.Lock()
require.Equal(t, len(sub.pendingTx.listeners), 0)
sub.pendingTx.mu.Unlock()
}
12 changes: 6 additions & 6 deletions api/subscriptions/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,32 +386,32 @@ func (s *Subscriptions) Mount(root *mux.Router, pathPrefix string) {

sub.Path("/txpool").
Methods(http.MethodGet).
Name("WS subscriptions/txpool").
Name("WS /subscriptions/txpool").
HandlerFunc(utils.WrapHandlerFunc(s.handlePendingTransactions))

sub.Path("/block").
Methods(http.MethodGet).
Name("WS subscriptions/block").
Name("WS /subscriptions/block").
HandlerFunc(utils.WrapHandlerFunc(s.websocket(s.handleBlockReader)))

sub.Path("/event").
Methods(http.MethodGet).
Name("WS subscriptions/event").
Name("WS /subscriptions/event").
HandlerFunc(utils.WrapHandlerFunc(s.websocket(s.handleEventReader)))

sub.Path("/transfer").
Methods(http.MethodGet).
Name("WS subscriptions/transfer").
Name("WS /subscriptions/transfer").
HandlerFunc(utils.WrapHandlerFunc(s.websocket(s.handleTransferReader)))

sub.Path("/beat2").
Methods(http.MethodGet).
Name("WS subscriptions/beat2").
Name("WS /subscriptions/beat2").
HandlerFunc(utils.WrapHandlerFunc(s.websocket(s.handleBeat2Reader)))

deprecatedBeat := sub.Path("/beat").
Methods(http.MethodGet).
Name("WS subscriptions/beat")
Name("WS /subscriptions/beat")

if s.enabledDeprecated {
deprecatedBeat.HandlerFunc(utils.WrapHandlerFunc(s.websocket(s.handleBeatReader)))
Expand Down

0 comments on commit 90c16b3

Please sign in to comment.