Skip to content

Commit a3cddca

Browse files
committed
itest: make unnecessarily async routine synchronous
We were previously setting up an asynchronous routine and the immediately blocking until the routine had finished. This commit simplifies the code by removing that unnecessary asynchronous setup.
1 parent 6ac107e commit a3cddca

File tree

1 file changed

+35
-47
lines changed

1 file changed

+35
-47
lines changed

itest/send_test.go

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,7 @@ func testReattemptFailedSendUniCourier(t *harnessTest) {
807807
// receiving an asset proof will be reattempted by the receiving tapd node. This
808808
// test targets the universe proof courier.
809809
func testReattemptFailedReceiveUniCourier(t *harnessTest) {
810-
var (
811-
ctxb = context.Background()
812-
wg sync.WaitGroup
813-
)
810+
ctxb := context.Background()
814811

815812
// This tapd node will send the asset to the receiving tapd node.
816813
// It will also transfer proof the related transfer proofs to the
@@ -892,56 +889,47 @@ func testReattemptFailedReceiveUniCourier(t *harnessTest) {
892889

893890
// Test to ensure that we receive the minimum expected number of backoff
894891
// wait event notifications.
895-
//
896-
// This test is executed in a goroutine to ensure that we can receive
897-
// the event notification(s) from the tapd node as soon as the proof
898-
// courier service is restarted.
899-
wg.Add(1)
900-
go func() {
901-
defer wg.Done()
902-
903-
// Define a target event selector to match the backoff wait
904-
// event. This function selects for a specific event type.
905-
targetEventSelector := func(event *taprpc.ReceiveAssetEvent) bool {
906-
switch eventTyped := event.Event.(type) {
907-
case *taprpc.ReceiveAssetEvent_ProofTransferBackoffWaitEvent:
908-
ev := eventTyped.ProofTransferBackoffWaitEvent
909-
910-
// We are attempting to identify receive
911-
// transfer types. Skip the event if it is not
912-
// a receiving transfer type.
913-
if ev.TransferType != taprpc.ProofTransferType_PROOF_TRANSFER_TYPE_RECEIVE {
914-
return false
915-
}
892+
t.Logf("Waiting for the receiving tapd node to complete backoff " +
893+
"proof retrieval attempts")
916894

917-
t.Logf("Found event ntfs: %v", ev)
918-
return true
895+
// Define a target event selector to match the backoff wait event. This
896+
// function selects for a specific event type.
897+
targetEventSelector := func(event *taprpc.ReceiveAssetEvent) bool {
898+
switch eventTyped := event.Event.(type) {
899+
case *taprpc.ReceiveAssetEvent_ProofTransferBackoffWaitEvent:
900+
ev := eventTyped.ProofTransferBackoffWaitEvent
901+
902+
// We are attempting to identify receive transfer types.
903+
// Skip the event if it is not a receiving transfer
904+
// type.
905+
if ev.TransferType != taprpc.ProofTransferType_PROOF_TRANSFER_TYPE_RECEIVE {
906+
return false
919907
}
920908

921-
return false
909+
t.Logf("Found event ntfs: %v", ev)
910+
return true
922911
}
923912

924-
// Expected minimum number of events to receive.
925-
expectedEventCount := 3
926-
927-
// Context timeout scales with expected number of events.
928-
timeout := time.Duration(expectedEventCount) *
929-
defaultProofTransferReceiverAckTimeout
930-
// Add overhead buffer to context timeout.
931-
timeout += 5 * time.Second
932-
ctx, cancel := context.WithTimeout(ctxb, timeout)
933-
defer cancel()
913+
return false
914+
}
934915

935-
assertAssetRecvNtfsEvent(
936-
t, ctx, eventNtfns, targetEventSelector,
937-
expectedEventCount,
938-
)
939-
}()
916+
// Expected minimum number of events to receive.
917+
expectedEventCount := 3
918+
919+
// Context timeout scales with expected number of events.
920+
timeout := time.Duration(expectedEventCount) *
921+
defaultProofTransferReceiverAckTimeout
922+
// Add overhead buffer to context timeout.
923+
timeout += 5 * time.Second
924+
ctx, cancel := context.WithTimeout(ctxb, timeout)
925+
defer cancel()
926+
927+
// Assert that the receiver tapd node has accomplished our minimum
928+
// expected number of backoff procedure receive attempts.
929+
assertAssetRecvNtfsEvent(
930+
t, ctx, eventNtfns, targetEventSelector, expectedEventCount,
931+
)
940932

941-
// Wait for the receiver node's backoff attempts to complete.
942-
t.Logf("Waiting for the receiving tapd node to complete backoff " +
943-
"proof retrieval attempts")
944-
wg.Wait()
945933
t.Logf("Finished waiting for the receiving tapd node to complete " +
946934
"backoff procedure")
947935

0 commit comments

Comments
 (0)