Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed data races #288

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions clients/gasManagement/gasStation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ func TestGasStation_RetryMechanism_FailsFirstRequests(t *testing.T) {
time.Sleep(time.Millisecond * 100)
assert.True(t, gs.loopStatus.IsSet())
assert.Equal(t, -1, gs.GetLatestGasPrice())
assert.Equal(t, 1, gs.fetchRetries) // first retry
gasPrice, err := gs.GetCurrentGasPrice()
assert.Equal(t, big.NewInt(0), gasPrice)
assert.Equal(t, ErrLatestGasPricesWereNotFetched, err)
Expand All @@ -238,7 +237,6 @@ func TestGasStation_RetryMechanism_FailsFirstRequests(t *testing.T) {
time.Sleep(time.Millisecond * 100)
assert.True(t, gs.loopStatus.IsSet())
assert.Equal(t, -1, gs.GetLatestGasPrice())
assert.Equal(t, 2, gs.fetchRetries) // second retry
gasPrice, err = gs.GetCurrentGasPrice()
assert.Equal(t, big.NewInt(0), gasPrice)
assert.Equal(t, ErrLatestGasPricesWereNotFetched, err)
Expand All @@ -247,16 +245,14 @@ func TestGasStation_RetryMechanism_FailsFirstRequests(t *testing.T) {
time.Sleep(time.Millisecond * 100)
assert.True(t, gs.loopStatus.IsSet())
assert.Equal(t, -1, gs.GetLatestGasPrice())
assert.Equal(t, 3, gs.fetchRetries) // third retry
gasPrice, err = gs.GetCurrentGasPrice()
assert.Equal(t, big.NewInt(0), gasPrice)
assert.Equal(t, ErrLatestGasPricesWereNotFetched, err)

chanOk <- struct{}{} // response is now ok
time.Sleep(time.Millisecond * 100)
assert.True(t, gs.loopStatus.IsSet())
assert.Equal(t, gs.GetLatestGasPrice(), 81)
assert.Equal(t, gs.fetchRetries, 0)
assert.Equal(t, 81, gs.GetLatestGasPrice())
gasPrice, err = gs.GetCurrentGasPrice()
assert.Equal(t, big.NewInt(int64(gs.GetLatestGasPrice()*args.GasPriceMultiplier)), gasPrice)
assert.Nil(t, err)
Expand Down
8 changes: 4 additions & 4 deletions factory/ethMultiversXBridgeComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,9 @@ func (components *ethMultiversXBridgeComponents) Start() error {
return err
}

go components.startBroadcastJoinRetriesLoop()
var ctx context.Context
ctx, components.cancelFunc = context.WithCancel(context.Background())
go components.startBroadcastJoinRetriesLoop(ctx)

return nil
}
Expand Down Expand Up @@ -772,12 +774,10 @@ func (components *ethMultiversXBridgeComponents) createAntifloodComponents(antif
return antiFloodComponents, nil
}

func (components *ethMultiversXBridgeComponents) startBroadcastJoinRetriesLoop() {
func (components *ethMultiversXBridgeComponents) startBroadcastJoinRetriesLoop(ctx context.Context) {
broadcastTimer := time.NewTimer(components.timeBeforeRepeatJoin)
defer broadcastTimer.Stop()

var ctx context.Context
ctx, components.cancelFunc = context.WithCancel(context.Background())
for {
broadcastTimer.Reset(components.timeBeforeRepeatJoin)

Expand Down
Loading