Skip to content

Commit

Permalink
Invert logical condition in WaitUntil functions (#1123)
Browse files Browse the repository at this point in the history
* Invert logic for bridge WaitUntil function

* Invert WaitUntil logic in TestCluster

* Change condition in TestE2E_Bridge_ChangeVotingPower
  • Loading branch information
Stefan-Ethernal authored Jan 16, 2023
1 parent 186aeaa commit 3c6e048
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
5 changes: 2 additions & 3 deletions e2e-polybft/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func TestE2E_CheckpointSubmission(t *testing.T) {

t.Logf("Checkpoint block: %d\n", actualCheckpointBlock)

return actualCheckpointBlock < expectedCheckpointBlock, nil
return actualCheckpointBlock == expectedCheckpointBlock, nil
}

// wait for a single epoch to be checkpointed
Expand Down Expand Up @@ -590,7 +590,6 @@ func TestE2E_Bridge_ChangeVotingPower(t *testing.T) {

t.Logf("Checkpoint block: %d\n", actualCheckpointBlock)

// waiting until condition is true (namely when block 20 gets checkpointed)
return actualCheckpointBlock < finalBlockNumber, nil
return actualCheckpointBlock == finalBlockNumber, nil
}))
}
2 changes: 1 addition & 1 deletion e2e-polybft/framework/test-bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (t *TestBridge) WaitUntil(pollFrequency, timeout time.Duration, handler fun
return err
}

if !isConditionMet {
if isConditionMet {
return nil
}
}
Expand Down
9 changes: 5 additions & 4 deletions e2e-polybft/framework/test-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (c *TestCluster) WaitUntil(dur time.Duration, handler func() bool) error {
case <-time.After(2 * time.Second):
}

if !handler() {
if handler() {
return nil
}
}
Expand Down Expand Up @@ -484,12 +484,13 @@ func (c *TestCluster) WaitForBlock(n uint64, timeout time.Duration) error {
func (c *TestCluster) WaitForGeneric(dur time.Duration, fn func(*TestServer) bool) error {
return c.WaitUntil(dur, func() bool {
for _, srv := range c.Servers {
if srv.isRunning() && !fn(srv) { // if server is stopped - skip it
return true
// query only running servers
if srv.isRunning() && !fn(srv) {
return false
}
}

return false
return true
})
}

Expand Down
6 changes: 3 additions & 3 deletions e2e-polybft/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func TestE2E_TxPool_Transfer(t *testing.T) {
}
t.Logf("Balance %s %s", receiver, balance)
if balance.Uint64() != uint64(sendAmount) {
return true
return false
}
}

return false
return true
})
require.NoError(t, err)
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func TestE2E_TxPool_Transfer_Linear(t *testing.T) {
return true
}

return balance.Cmp(big.NewInt(0)) == 0
return balance.Cmp(big.NewInt(0)) > 0
})

return err
Expand Down

0 comments on commit 3c6e048

Please sign in to comment.