black_hole_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2017 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // +build !cluster_proxy
  15. package integration
  16. import (
  17. "context"
  18. "testing"
  19. "time"
  20. "github.com/coreos/etcd/clientv3"
  21. "github.com/coreos/etcd/integration"
  22. "github.com/coreos/etcd/pkg/testutil"
  23. )
  24. func TestBlackholePutWithoutKeealiveEnabled(t *testing.T) {
  25. defer testutil.AfterTest(t)
  26. clus := integration.NewClusterV3(t, &integration.ClusterConfig{
  27. Size: 2,
  28. GRPCKeepAliveMinTime: 1 * time.Millisecond,
  29. SkipCreatingClient: true},
  30. ) // avoid too_many_pings
  31. defer clus.Terminate(t)
  32. ccfg := clientv3.Config{
  33. Endpoints: []string{clus.Members[0].GRPCAddr()},
  34. DialTimeout: 1 * time.Second,
  35. }
  36. cli, err := clientv3.New(ccfg)
  37. if err != nil {
  38. t.Fatal(err)
  39. }
  40. defer cli.Close()
  41. // wait for ep[0] to be pinned
  42. waitPinReady(t, cli)
  43. cli.SetEndpoints(clus.Members[0].GRPCAddr(), clus.Members[1].GRPCAddr())
  44. clus.Members[0].Blackhole()
  45. // fail first due to blackhole, retry should succeed
  46. // when gRPC supports better retry on non-delivered request, the first put can succeed.
  47. ctx, c1 := context.WithTimeout(context.Background(), time.Second)
  48. defer c1()
  49. if _, err = cli.Put(ctx, "foo", "bar"); err != context.DeadlineExceeded {
  50. t.Fatalf("err = %v, want %v", err, context.DeadlineExceeded)
  51. }
  52. ctx, c2 := context.WithTimeout(context.Background(), time.Second)
  53. defer c2()
  54. if _, err = cli.Put(ctx, "foo", "bar"); err != nil {
  55. t.Errorf("put failed with error %v", err)
  56. }
  57. }