Skip to content

Commit

Permalink
fix: fix testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
newborn22 committed Dec 3, 2024
1 parent c49a1ff commit cca04d6
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions endtoend/branch/branch_test.go
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
}

0 comments on commit cca04d6

Please sign in to comment.