Merge pull request #17235 from fuweid/fix-17223

integration: deflake TestMaintenanceSnapshotCancel
This commit is contained in:
Benjamin Wang 2024-01-14 13:24:50 +00:00 committed by GitHub
commit c8b4b168af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,6 +26,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest" "go.uber.org/zap/zaptest"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -176,6 +177,12 @@ func TestMaintenanceSnapshotCancel(t *testing.T) {
} }
defer rc1.Close() 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() cancel()
_, err = io.Copy(io.Discard, rc1) _, err = io.Copy(io.Discard, rc1)
if err != context.Canceled { if err != context.Canceled {