-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
62 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,70 @@ | ||
package wasm | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"context" | ||
"testing" | ||
"time" | ||
) | ||
|
||
func TestSourceAndTargetClusterConnection(t *testing.T) { | ||
assert.NoError(t, sourceCluster.MysqlDb.Ping()) | ||
assert.NoError(t, sourceCluster.WescaleDb.Ping()) | ||
assert.NoError(t, targetCluster.MysqlDb.Ping()) | ||
assert.NoError(t, targetCluster.WescaleDb.Ping()) | ||
// Create context with 10-minute timeout | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute) | ||
defer cancel() | ||
|
||
// Define retry interval | ||
retryInterval := 5 * time.Second | ||
|
||
// Channel for completion signal | ||
done := make(chan bool) | ||
|
||
// Run connection tests in goroutine | ||
go func() { | ||
for { | ||
select { | ||
case <-ctx.Done(): | ||
// Timeout or cancelled | ||
t.Error("Connection test timeout") | ||
done <- true | ||
return | ||
default: | ||
// Test source cluster connection | ||
err := sourceCluster.MysqlDb.Ping() | ||
if err != nil { | ||
t.Logf("Source cluster MySQL connection failed: %v", err) | ||
time.Sleep(retryInterval) | ||
continue | ||
} | ||
|
||
err = sourceCluster.WescaleDb.Ping() | ||
if err != nil { | ||
t.Logf("Source cluster Wescale connection failed: %v", err) | ||
time.Sleep(retryInterval) | ||
continue | ||
} | ||
|
||
// Test target cluster connection | ||
err = targetCluster.MysqlDb.Ping() | ||
if err != nil { | ||
t.Logf("Target cluster MySQL connection failed: %v", err) | ||
time.Sleep(retryInterval) | ||
continue | ||
} | ||
|
||
err = targetCluster.WescaleDb.Ping() | ||
if err != nil { | ||
t.Logf("Target cluster Wescale connection failed: %v", err) | ||
time.Sleep(retryInterval) | ||
continue | ||
} | ||
|
||
// All connections successful | ||
t.Log("All cluster connections test passed") | ||
done <- true | ||
return | ||
} | ||
} | ||
}() | ||
|
||
// Wait for test completion or timeout | ||
<-done | ||
} |