From 4312f9597881a8c36dd8e7dd5e79c3cf71adb9c3 Mon Sep 17 00:00:00 2001 From: William Banfield Date: Fri, 3 Dec 2021 09:44:48 -0500 Subject: [PATCH] refactor to use new ensure helper function --- internal/consensus/common_test.go | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index b4c0b503a..d5fae3c9d 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -682,10 +682,16 @@ func ensureRelock(t *testing.T, relockCh <-chan tmpubsub.Message, height int64, } func ensureProposal(t *testing.T, proposalCh <-chan tmpubsub.Message, height int64, round int32, propID types.BlockID) { + ensureProposalWithTimeout(t, proposalCh, height, round, propID, ensureTimeout) +} + +func ensureProposalWithTimeout(t *testing.T, proposalCh <-chan tmpubsub.Message, height int64, round int32, propID types.BlockID, timeout time.Duration) { + t.Helper() msg := ensureMessageBeforeTimeout(t, proposalCh, ensureTimeout) proposalEvent, ok := msg.Data().(types.EventDataCompleteProposal) if !ok { - t.Fatalf("expected a EventDataCompleteProposal, got %T. Wrong subscription channel?", msg.Data()) + t.Fatalf("expected a EventDataCompleteProposal, got %T. Wrong subscription channel?", + msg.Data()) } if proposalEvent.Height != height { t.Fatalf("expected height %v, got %v", height, proposalEvent.Height) @@ -697,29 +703,6 @@ func ensureProposal(t *testing.T, proposalCh <-chan tmpubsub.Message, height int t.Fatalf("Proposed block does not match expected block (%v != %v)", proposalEvent.BlockID, propID) } } - -func ensureProposalWithTimeout(t *testing.T, proposalCh <-chan tmpubsub.Message, height int64, round int32, propID types.BlockID, timeout time.Duration) { - t.Helper() - select { - case <-time.After(timeout): - t.Fatalf("Timeout expired while waiting for NewProposal event") - case msg := <-proposalCh: - proposalEvent, ok := msg.Data().(types.EventDataCompleteProposal) - if !ok { - t.Fatalf("expected a EventDataCompleteProposal, got %T. Wrong subscription channel?", - msg.Data()) - } - if proposalEvent.Height != height { - t.Fatalf("expected height %v, got %v", height, proposalEvent.Height) - } - if proposalEvent.Round != round { - t.Fatalf("expected round %v, got %v", round, proposalEvent.Round) - } - if !proposalEvent.BlockID.Equals(propID) { - t.Fatalf("Proposed block does not match expected block (%v != %v)", proposalEvent.BlockID, propID) - } - } -} func ensurePrecommit(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32) { t.Helper() ensureVote(t, voteCh, height, round, tmproto.PrecommitType)