Skip to content

Commit

Permalink
added test case where server is restarted and ongoing Put succeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
AngstyDuck committed Sep 6, 2023
1 parent 976cff5 commit 011d138
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tests/integration/clientv3/concurrency/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
package concurrency_test

import (
"context"
// "context"
"testing"
"time"

"github.com/stretchr/testify/assert"
// "github.com/stretchr/testify/assert"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3/concurrency"
integration2 "go.etcd.io/etcd/tests/v3/framework/integration"
clientv3test "go.etcd.io/etcd/tests/v3/integration/clientv3"
)

/*
func TestSessionOptions(t *testing.T) {
cli, err := integration2.NewClient(t, clientv3.Config{Endpoints: exampleEndpoints()})
if err != nil {
Expand Down Expand Up @@ -144,14 +145,16 @@ func TestCreationTimeout(t *testing.T) {
_, err = logOb.Expect(context.Background(), "Subchannel Connectivity change to TRANSIENT_FAILURE", 3)
assert.Nil(t, err)
}
*/

// TestCreationTimeout checks that the option WithCreationTimeout
// sets a timeout for the creation of new sessions
// TestTimeoutDoesntAffectSubsequentConnections checks that the option WithCreationTimeout
// is only used when Session is created
func TestTimeoutDoesntAffectSubsequentConnections(t *testing.T) {
integration2.BeforeTest(t)

// create new cluster
clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 1})
defer clus.Terminate(t)

// create new client
cli, err := integration2.NewClient(t, clientv3.Config{Endpoints: []string{clus.Members[0].GRPCURL()}})
Expand All @@ -167,7 +170,7 @@ func TestTimeoutDoesntAffectSubsequentConnections(t *testing.T) {
s, err := concurrency.NewSession(cli, concurrency.WithCreationTimeout(1*time.Second))

// terminating the cluster
clus.Terminate(t)
clus.Members[0].Terminate(t)

donec := make(chan struct{})
go func() {
Expand All @@ -182,4 +185,12 @@ func TestTimeoutDoesntAffectSubsequentConnections(t *testing.T) {
// that timeout is not used by the Put operation
case <-time.After(2 * time.Second):
}

// restarting and ensuring that the Put operation will eventually succeed
clus.Members[0].Restart(t)
select {
case <-donec:
case <-time.After(1 * time.Second):
t.Fatal("Put function hung even after restarting cluster")
}
}

0 comments on commit 011d138

Please sign in to comment.