From fdf1e28a3fbfbbae57160e3dc2b15cc1c7c465c0 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Fri, 12 Jan 2024 19:24:10 +0800 Subject: [PATCH] integration: deflake TestMaintenanceSnapshotCancel Unlike SnapshotWithVersion, the client.Snapshot doesn't wait for first response. The server could open db after we close connection or shutdown the server. We can read few bytes to ensure server opens boltdb. Signed-off-by: Wei Fu --- tests/integration/clientv3/maintenance_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/integration/clientv3/maintenance_test.go b/tests/integration/clientv3/maintenance_test.go index e5c9812f8..8aa275bb9 100644 --- a/tests/integration/clientv3/maintenance_test.go +++ b/tests/integration/clientv3/maintenance_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.uber.org/zap/zaptest" "google.golang.org/grpc" @@ -176,6 +177,12 @@ func TestMaintenanceSnapshotCancel(t *testing.T) { } defer rc1.Close() + // read 16 bytes to ensure that server opens snapshot + buf := make([]byte, 16) + n, err := rc1.Read(buf) + assert.NoError(t, err) + assert.Equal(t, 16, n) + cancel() _, err = io.Copy(io.Discard, rc1) if err != context.Canceled {