@@ -12,12 +12,13 @@ import (
1212
1313// TestMain provides setup and teardown for the entire test suite
1414func TestMain (m * testing.M ) {
15- mgr := GetDefaultMgr ()
16-
1715 // Run tests
1816 code := m .Run ()
1917
20- mgr .Close ()
18+ // Cleanup: close the current default manager and wait for shutdown
19+ currentMgr := GetDefaultMgr ()
20+ currentMgr .Close ()
21+ currentMgr .WaitForShutdown ()
2122
2223 if code != 0 {
2324 panic (fmt .Sprintf ("Tests failed with code %d" , code ))
@@ -1086,14 +1087,17 @@ func TestWithResolvers(t *testing.T) {
10861087 t .Run ("Multiple resolves should only take first" , func (t * testing.T ) {
10871088 promise , resolve , _ := WithResolvers [string ]()
10881089
1090+ // Use a channel to ensure the first resolve happens before the second
1091+ firstDone := make (chan struct {})
1092+
10891093 // Multiple resolves
10901094 go func () {
1091- time .Sleep (5 * time .Millisecond )
10921095 resolve ("first" )
1096+ close (firstDone )
10931097 }()
10941098 go func () {
1095- time . Sleep ( 10 * time . Millisecond )
1096- resolve ("second" )
1099+ <- firstDone // Wait for first resolve to complete
1100+ resolve ("second" ) // This should be ignored
10971101 }()
10981102
10991103 result , err := promise .Await ()
@@ -1108,14 +1112,17 @@ func TestWithResolvers(t *testing.T) {
11081112 t .Run ("Multiple rejects should only take first" , func (t * testing.T ) {
11091113 promise , _ , reject := WithResolvers [string ]()
11101114
1115+ // Use a channel to ensure the first reject happens before the second
1116+ firstDone := make (chan struct {})
1117+
11111118 // Multiple rejects
11121119 go func () {
1113- time .Sleep (5 * time .Millisecond )
11141120 reject (errors .New ("first reject" ))
1121+ close (firstDone )
11151122 }()
11161123 go func () {
1117- time . Sleep ( 10 * time . Millisecond )
1118- reject (errors .New ("second reject" ))
1124+ <- firstDone // Wait for first reject to complete
1125+ reject (errors .New ("second reject" )) // This should be ignored
11191126 }()
11201127
11211128 _ , err := promise .Await ()
0 commit comments