@@ -816,44 +816,30 @@ func TestFlakyProvider(t *testing.T) {
816816 wg .Add (1 )
817817 go func (signedTxn * types.Transaction ) {
818818 defer wg .Done ()
819+ txnHash := signedTxn .Hash ()
819820
820- // Delay sending the transaction to ensure the subscriber is ready
821- time .Sleep (2 * time .Second )
822-
823- // Using the trusted provider here to ensure txn is sent
824- ethtxn .SendTransaction (ctx , goodProvider , signedTxn )
825- require .NoError (t , err )
826- }(signedTxn )
827-
828- wg .Add (1 )
829- go func (signedTxn * types.Transaction ) {
830- defer wg .Done ()
831-
832- receiptsFilter := ethreceipts .FilterTxnHash (
833- signedTxn .Hash (),
834- )
835-
836- sub := receiptsListener .Subscribe (
837- receiptsFilter ,
838- )
821+ receiptsFilter := ethreceipts .FilterTxnHash (txnHash )
822+ sub := receiptsListener .Subscribe (receiptsFilter )
839823 defer sub .Unsubscribe ()
840824
825+ _ , _ , err := ethtxn .SendTransaction (ctx , goodProvider , signedTxn )
826+ require .NoError (t , err , "failed to send transaction %s" , txnHash .String ())
827+
841828 start := time .Now ()
842829 select {
843830 case <- ctx .Done ():
844- t .Fatalf ("Context done: %v" , ctx .Err ())
831+ t .Errorf ("Context done while waiting for txn %s : %v" , txnHash . String () , ctx .Err ())
845832 case <- sub .Done ():
846- t .Fatal ("Subscription closed unexpectedly" )
833+ t .Errorf ("Subscription closed unexpectedly for txn %s" , txnHash . String () )
847834 case receipt := <- sub .TransactionReceipt ():
848835 activeSubs := receiptsListener .NumSubscribers ()
849- t .Logf ("Filter matched txn %s after %s, active subs: %d" , signedTxn . Hash () .String (), time .Since (start ), activeSubs )
850- require .Equal (t , signedTxn . Hash () , receipt .TransactionHash ())
836+ t .Logf ("Filter matched txn %s after %s, active subs: %d" , txnHash .String (), time .Since (start ), activeSubs )
837+ require .Equal (t , txnHash , receipt .TransactionHash ())
851838 require .Equal (t , uint64 (1 ), receipt .Status ())
852839 case <- time .After (300 * time .Second ):
853- t .Fatal ("Timeout waiting for filter to match txn" )
840+ t .Errorf ("Timeout waiting for filter to match txn %s" , txnHash . String () )
854841 }
855842 }(signedTxn )
856-
857843 }
858844
859845 t .Logf ("Waiting for all goroutines to complete..." )
@@ -933,44 +919,30 @@ func TestFlakyProvider(t *testing.T) {
933919 wg .Add (1 )
934920 go func (signedTxn * types.Transaction ) {
935921 defer wg .Done ()
922+ txnHash := signedTxn .Hash ()
936923
937- // Delay sending the transaction to ensure the subscriber is ready
938- time .Sleep (2 * time .Second )
939-
940- // Using the trusted provider here to ensure txn is sent
941- ethtxn .SendTransaction (ctx , goodProvider , signedTxn )
942- require .NoError (t , err )
943- }(signedTxn )
944-
945- wg .Add (1 )
946- go func (signedTxn * types.Transaction ) {
947- defer wg .Done ()
948-
949- receiptsFilter := ethreceipts .FilterTxnHash (
950- signedTxn .Hash (),
951- )
952-
953- sub := receiptsListener .Subscribe (
954- receiptsFilter ,
955- )
924+ receiptsFilter := ethreceipts .FilterTxnHash (txnHash )
925+ sub := receiptsListener .Subscribe (receiptsFilter )
956926 defer sub .Unsubscribe ()
957927
928+ _ , _ , err := ethtxn .SendTransaction (ctx , goodProvider , signedTxn )
929+ require .NoError (t , err , "failed to send transaction %s" , txnHash .String ())
930+
958931 start := time .Now ()
959932 select {
960933 case <- ctx .Done ():
961- t .Fatalf ("Context done: %v" , ctx .Err ())
934+ t .Errorf ("Context done while waiting for txn %s : %v" , txnHash . String () , ctx .Err ())
962935 case <- sub .Done ():
963- t .Fatal ("Subscription closed unexpectedly" )
936+ t .Errorf ("Subscription closed unexpectedly for txn %s" , txnHash . String () )
964937 case receipt := <- sub .TransactionReceipt ():
965938 activeSubs := receiptsListener .NumSubscribers ()
966- t .Logf ("Filter matched txn %s after %s, active subs: %d" , signedTxn . Hash () .String (), time .Since (start ), activeSubs )
967- require .Equal (t , signedTxn . Hash () , receipt .TransactionHash ())
939+ t .Logf ("Filter matched txn %s after %s, active subs: %d" , txnHash .String (), time .Since (start ), activeSubs )
940+ require .Equal (t , txnHash , receipt .TransactionHash ())
968941 require .Equal (t , uint64 (1 ), receipt .Status ())
969942 case <- time .After (300 * time .Second ):
970- t .Fatal ("Timeout waiting for filter to match txn" )
943+ t .Errorf ("Timeout waiting for filter to match txn %s" , txnHash . String () )
971944 }
972945 }(signedTxn )
973-
974946 }
975947
976948 t .Logf ("Waiting for all goroutines to complete..." )
@@ -1050,44 +1022,30 @@ func TestFlakyProvider(t *testing.T) {
10501022 wg .Add (1 )
10511023 go func (signedTxn * types.Transaction ) {
10521024 defer wg .Done ()
1025+ txnHash := signedTxn .Hash ()
10531026
1054- // Delay sending the transaction to ensure the subscriber is ready
1055- time .Sleep (2 * time .Second )
1056-
1057- // Using the trusted provider here to ensure txn is sent
1058- ethtxn .SendTransaction (ctx , goodProvider , signedTxn )
1059- require .NoError (t , err )
1060- }(signedTxn )
1061-
1062- wg .Add (1 )
1063- go func (signedTxn * types.Transaction ) {
1064- defer wg .Done ()
1065-
1066- receiptsFilter := ethreceipts .FilterTxnHash (
1067- signedTxn .Hash (),
1068- )
1069-
1070- sub := receiptsListener .Subscribe (
1071- receiptsFilter ,
1072- )
1027+ receiptsFilter := ethreceipts .FilterTxnHash (txnHash )
1028+ sub := receiptsListener .Subscribe (receiptsFilter )
10731029 defer sub .Unsubscribe ()
10741030
1031+ _ , _ , err := ethtxn .SendTransaction (ctx , goodProvider , signedTxn )
1032+ require .NoError (t , err , "failed to send transaction %s" , txnHash .String ())
1033+
10751034 start := time .Now ()
10761035 select {
10771036 case <- ctx .Done ():
1078- t .Fatalf ("Context done: %v" , ctx .Err ())
1037+ t .Errorf ("Context done while waiting for txn %s : %v" , txnHash . String () , ctx .Err ())
10791038 case <- sub .Done ():
1080- t .Fatal ("Subscription closed unexpectedly" )
1039+ t .Errorf ("Subscription closed unexpectedly for txn %s" , txnHash . String () )
10811040 case receipt := <- sub .TransactionReceipt ():
10821041 activeSubs := receiptsListener .NumSubscribers ()
1083- t .Logf ("Filter matched txn %s after %s, active subs: %d" , signedTxn . Hash () .String (), time .Since (start ), activeSubs )
1084- require .Equal (t , signedTxn . Hash () , receipt .TransactionHash ())
1042+ t .Logf ("Filter matched txn %s after %s, active subs: %d" , txnHash .String (), time .Since (start ), activeSubs )
1043+ require .Equal (t , txnHash , receipt .TransactionHash ())
10851044 require .Equal (t , uint64 (1 ), receipt .Status ())
10861045 case <- time .After (300 * time .Second ):
1087- t .Fatal ("Timeout waiting for filter to match txn" )
1046+ t .Errorf ("Timeout waiting for filter to match txn %s" , txnHash . String () )
10881047 }
10891048 }(signedTxn )
1090-
10911049 }
10921050
10931051 t .Logf ("Waiting for all goroutines to complete..." )
@@ -1167,44 +1125,30 @@ func TestFlakyProvider(t *testing.T) {
11671125 wg .Add (1 )
11681126 go func (signedTxn * types.Transaction ) {
11691127 defer wg .Done ()
1128+ txnHash := signedTxn .Hash ()
11701129
1171- // Delay sending the transaction to ensure the subscriber is ready
1172- time .Sleep (2 * time .Second )
1173-
1174- // Using the trusted provider here to ensure txn is sent
1175- ethtxn .SendTransaction (ctx , goodProvider , signedTxn )
1176- require .NoError (t , err )
1177- }(signedTxn )
1178-
1179- wg .Add (1 )
1180- go func (signedTxn * types.Transaction ) {
1181- defer wg .Done ()
1182-
1183- receiptsFilter := ethreceipts .FilterTxnHash (
1184- signedTxn .Hash (),
1185- )
1186-
1187- sub := receiptsListener .Subscribe (
1188- receiptsFilter ,
1189- )
1130+ receiptsFilter := ethreceipts .FilterTxnHash (txnHash )
1131+ sub := receiptsListener .Subscribe (receiptsFilter )
11901132 defer sub .Unsubscribe ()
11911133
1134+ _ , _ , err := ethtxn .SendTransaction (ctx , goodProvider , signedTxn )
1135+ require .NoError (t , err , "failed to send transaction %s" , txnHash .String ())
1136+
11921137 start := time .Now ()
11931138 select {
11941139 case <- ctx .Done ():
1195- t .Fatalf ("Context done: %v" , ctx .Err ())
1140+ t .Errorf ("Context done while waiting for txn %s : %v" , txnHash . String () , ctx .Err ())
11961141 case <- sub .Done ():
1197- t .Fatal ("Subscription closed unexpectedly" )
1142+ t .Errorf ("Subscription closed unexpectedly for txn %s" , txnHash . String () )
11981143 case receipt := <- sub .TransactionReceipt ():
11991144 activeSubs := receiptsListener .NumSubscribers ()
1200- t .Logf ("Filter matched txn %s after %s, active subs: %d" , signedTxn . Hash () .String (), time .Since (start ), activeSubs )
1201- require .Equal (t , signedTxn . Hash () , receipt .TransactionHash ())
1145+ t .Logf ("Filter matched txn %s after %s, active subs: %d" , txnHash .String (), time .Since (start ), activeSubs )
1146+ require .Equal (t , txnHash , receipt .TransactionHash ())
12021147 require .Equal (t , uint64 (1 ), receipt .Status ())
12031148 case <- time .After (300 * time .Second ):
1204- t .Fatal ("Timeout waiting for filter to match txn" )
1149+ t .Errorf ("Timeout waiting for filter to match txn %s" , txnHash . String () )
12051150 }
12061151 }(signedTxn )
1207-
12081152 }
12091153
12101154 t .Logf ("Waiting for all goroutines to complete..." )
0 commit comments