Skip to content

Commit

Permalink
Merge pull request #3961 from riemannulus/test/fix/swarmtest/evidence…
Browse files Browse the repository at this point in the history
…/do-not-use-exception-in-tests

🔧  fix: use `Assert` instead of exception
  • Loading branch information
riemannulus authored Oct 8, 2024
2 parents 9bd2216 + b888929 commit bfd304b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions test/Libplanet.Net.Tests/SwarmTest.Evidence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public async Task DuplicateVote_Test()
var context = consensusContext.CurrentContext;
var bindingFlags = BindingFlags.Instance | BindingFlags.NonPublic;
var methodName = "PublishMessage";
var methodInfo = context.GetType().GetMethod(methodName, bindingFlags) ??
throw new InvalidOperationException(
$"{nameof(Context)} does not have a method named {methodName}.");
var methodInfo = context.GetType().GetMethod(methodName, bindingFlags);

Assert.NotNull(methodInfo);

var vote = MakeRandomVote(privateKeys[0], height, round, VoteFlag.PreVote);
var args = new object[] { new ConsensusPreVoteMsg(vote) };

Expand All @@ -90,18 +91,18 @@ public async Task DuplicateVote_Test()
}
}

if (i == 10)
{
throw new InvalidOperationException("Evidence are not broadcasted.");
}
Assert.NotEqual(10, i);

var waitTasks2 = blockChains.Select(item => WaitUntilBlockIndexAsync(item, i));
await Task.WhenAll(waitTasks2);
Array.ForEach(blockChains, item => Assert.Equal(i + 1, item.Count));
foreach (BlockChain blockChain in blockChains)
{
Assert.Equal(i + 1, blockChain.Count);
}
}
finally
{
var cleanTasks = swarms.Select(item => StopAsync(item));
var cleanTasks = swarms.Select(StopAsync);
await Task.WhenAll(cleanTasks);
}
}
Expand Down

0 comments on commit bfd304b

Please sign in to comment.