File tree Expand file tree Collapse file tree 1 file changed +18
-12
lines changed
clients/tfchain-client-go Expand file tree Collapse file tree 1 file changed +18
-12
lines changed Original file line number Diff line number Diff line change 1
1
package substrate
2
2
3
3
import (
4
+ "sync"
4
5
"testing"
5
- "time"
6
6
7
7
"github.com/stretchr/testify/assert"
8
8
"github.com/stretchr/testify/require"
@@ -86,27 +86,33 @@ func TestFailoverMechanism(t *testing.T) {
86
86
sub1 .cl .Client .Close ()
87
87
sub2 .cl .Client .Close ()
88
88
89
+ // Create WaitGroup to ensure all goroutines complete before test ends
90
+ var wg sync.WaitGroup
91
+ wg .Add (2 )
92
+
89
93
// Try to use both connections concurrently
90
- done := make (chan bool )
94
+ errs := make (chan error , 2 )
91
95
go func () {
96
+ defer wg .Done ()
92
97
_ , err := sub1 .Time ()
93
- assert .NoError (t , err )
94
- done <- true
98
+ errs <- err
95
99
}()
96
100
97
101
go func () {
102
+ defer wg .Done ()
98
103
_ , err := sub2 .Time ()
99
- assert .NoError (t , err )
100
- done <- true
104
+ errs <- err
101
105
}()
102
106
103
107
// Wait for both operations to complete
104
- for i := 0 ; i < 2 ; i ++ {
105
- select {
106
- case <- done :
107
- case <- time .After (5 * time .Second ):
108
- t .Fatal ("timeout waiting for concurrent failover" )
109
- }
108
+ go func () {
109
+ wg .Wait ()
110
+ close (errs )
111
+ }()
112
+
113
+ // Check errors from both goroutines
114
+ for err := range errs {
115
+ require .NoError (t , err )
110
116
}
111
117
})
112
118
}
You can’t perform that action at this time.
0 commit comments