MCPcopy
hub / github.com/etcd-io/etcd / TestTxnWriteFail

Function TestTxnWriteFail

tests/integration/clientv3/txn_test.go:56–102  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestTxnWriteFail(t *testing.T) {
57 integration2.BeforeTest(t)
58
59 clus := integration2.NewCluster(t, &integration2.ClusterConfig{Size: 3, UseBridge: true})
60 defer clus.Terminate(t)
61
62 kv := clus.Client(0)
63
64 clus.Members[0].Stop(t)
65
66 txnc, getc := make(chan struct{}), make(chan struct{})
67 go func() {
68 ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
69 defer cancel()
70 resp, err := kv.Txn(ctx).Then(clientv3.OpPut("foo", "bar")).Commit()
71 if err == nil {
72 t.Errorf("expected error, got response %v", resp)
73 }
74 close(txnc)
75 }()
76
77 go func() {
78 defer close(getc)
79 select {
80 case <-time.After(5 * time.Second):
81 t.Errorf("timed out waiting for txn fail")
82 case <-txnc:
83 }
84 // and ensure the put didn't take
85 gresp, gerr := clus.Client(1).Get(context.TODO(), "foo")
86 if gerr != nil {
87 t.Error(gerr)
88 }
89 if len(gresp.Kvs) != 0 {
90 t.Errorf("expected no keys, got %v", gresp.Kvs)
91 }
92 }()
93
94 select {
95 case <-time.After(5 * clus.Members[1].ServerConfig.ReqTimeout()):
96 t.Fatalf("timed out waiting for get")
97 case <-getc:
98 }
99
100 // reconnect so terminate doesn't complain about double-close
101 clus.Members[0].Restart(t)
102}
103
104func TestTxnReadRetry(t *testing.T) {
105 t.Skipf("skipping txn read retry test: re-enable after we do retry on txn read request")

Callers

nothing calls this directly

Calls 14

TerminateMethod · 0.95
ClientMethod · 0.95
BeforeTestMethod · 0.65
NewClusterMethod · 0.65
StopMethod · 0.65
CommitMethod · 0.65
ThenMethod · 0.65
TxnMethod · 0.65
ErrorfMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.65
ReqTimeoutMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…