Skip to content

Commit

Permalink
fix: race condition on close server
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad committed Jan 13, 2025
1 parent a217a24 commit 0969e39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion www/zmq/block_info_publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestBlockInfoPublisher(t *testing.T) {
td := setup(t)
t.Cleanup(td.cleanup())
defer td.cleanup()

port := td.FindFreePort()
addr := fmt.Sprintf("tcp://localhost:%d", port)
Expand Down
38 changes: 19 additions & 19 deletions www/zmq/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,22 @@ func (ts *testData) cleanup() func() {
}

func TestServerWithDefaultConfig(t *testing.T) {
suite := setup(t)
td := setup(t)

conf := DefaultConfig()

err := suite.initServer(context.TODO(), conf)
t.Cleanup(suite.cleanup())
err := td.initServer(context.TODO(), conf)
defer td.cleanup()

assert.NoError(t, err)
require.NotNil(t, suite.server)
require.NotNil(t, td.server)
}

func TestTopicsWithSameSocket(t *testing.T) {
suite := setup(t)
t.Cleanup(suite.cleanup())
td := setup(t)
defer td.cleanup()

port := suite.FindFreePort()
port := td.FindFreePort()
addr := fmt.Sprintf("tcp://127.0.0.1:%d", port)

conf := DefaultConfig()
Expand All @@ -81,30 +81,30 @@ func TestTopicsWithSameSocket(t *testing.T) {
conf.ZmqPubRawBlock = addr
conf.ZmqPubRawTx = addr

err := suite.initServer(context.TODO(), conf)
err := td.initServer(context.TODO(), conf)
require.NoError(t, err)

require.Len(t, suite.server.publishers, 4)
require.Len(t, td.server.publishers, 4)

expectedAddr := suite.server.publishers[0].Address()
expectedAddr := td.server.publishers[0].Address()

for _, pub := range suite.server.publishers {
for _, pub := range td.server.publishers {
require.Equal(t, expectedAddr, pub.Address(), "All publishers must have the same address")
}
}

func TestTopicsWithDifferentSockets(t *testing.T) {
suite := setup(t)
t.Cleanup(suite.cleanup())
td := setup(t)
defer td.cleanup()

conf := DefaultConfig()
conf.ZmqPubBlockInfo = fmt.Sprintf("tcp://127.0.0.1:%d", suite.FindFreePort())
conf.ZmqPubTxInfo = fmt.Sprintf("tcp://127.0.0.1:%d", suite.FindFreePort())
conf.ZmqPubRawBlock = fmt.Sprintf("tcp://127.0.0.1:%d", suite.FindFreePort())
conf.ZmqPubRawTx = fmt.Sprintf("tcp://127.0.0.1:%d", suite.FindFreePort())
conf.ZmqPubBlockInfo = fmt.Sprintf("tcp://127.0.0.1:%d", td.FindFreePort())
conf.ZmqPubTxInfo = fmt.Sprintf("tcp://127.0.0.1:%d", td.FindFreePort())
conf.ZmqPubRawBlock = fmt.Sprintf("tcp://127.0.0.1:%d", td.FindFreePort())
conf.ZmqPubRawTx = fmt.Sprintf("tcp://127.0.0.1:%d", td.FindFreePort())

err := suite.initServer(context.TODO(), conf)
err := td.initServer(context.TODO(), conf)
require.NoError(t, err)

require.Len(t, suite.server.publishers, 4)
require.Len(t, td.server.publishers, 4)
}

0 comments on commit 0969e39

Please sign in to comment.