mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tests: use separate errc for each case in TestTxnPanics
Signed-off-by: Msk <118117161+Mskxn@users.noreply.github.com>
This commit is contained in:
parent
f7af6b64ba
commit
a3743a79bc
@ -27,8 +27,7 @@ func TestTxnPanics(t *testing.T) {
|
|||||||
|
|
||||||
kv := &kv{}
|
kv := &kv{}
|
||||||
|
|
||||||
errc := make(chan string, 6)
|
df := func(errc chan string) {
|
||||||
df := func() {
|
|
||||||
if s := recover(); s != nil {
|
if s := recover(); s != nil {
|
||||||
errc <- s.(string)
|
errc <- s.(string)
|
||||||
}
|
}
|
||||||
@ -38,53 +37,53 @@ func TestTxnPanics(t *testing.T) {
|
|||||||
op := OpPut("foo", "bar")
|
op := OpPut("foo", "bar")
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
f func()
|
f func(chan string)
|
||||||
|
|
||||||
err string
|
err string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
f: func() {
|
f: func(errc chan string) {
|
||||||
defer df()
|
defer df(errc)
|
||||||
kv.Txn(context.TODO()).If(cmp).If(cmp)
|
kv.Txn(context.TODO()).If(cmp).If(cmp)
|
||||||
},
|
},
|
||||||
|
|
||||||
err: "cannot call If twice!",
|
err: "cannot call If twice!",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: func() {
|
f: func(errc chan string) {
|
||||||
defer df()
|
defer df(errc)
|
||||||
kv.Txn(context.TODO()).Then(op).If(cmp)
|
kv.Txn(context.TODO()).Then(op).If(cmp)
|
||||||
},
|
},
|
||||||
|
|
||||||
err: "cannot call If after Then!",
|
err: "cannot call If after Then!",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: func() {
|
f: func(errc chan string) {
|
||||||
defer df()
|
defer df(errc)
|
||||||
kv.Txn(context.TODO()).Else(op).If(cmp)
|
kv.Txn(context.TODO()).Else(op).If(cmp)
|
||||||
},
|
},
|
||||||
|
|
||||||
err: "cannot call If after Else!",
|
err: "cannot call If after Else!",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: func() {
|
f: func(errc chan string) {
|
||||||
defer df()
|
defer df(errc)
|
||||||
kv.Txn(context.TODO()).Then(op).Then(op)
|
kv.Txn(context.TODO()).Then(op).Then(op)
|
||||||
},
|
},
|
||||||
|
|
||||||
err: "cannot call Then twice!",
|
err: "cannot call Then twice!",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: func() {
|
f: func(errc chan string) {
|
||||||
defer df()
|
defer df(errc)
|
||||||
kv.Txn(context.TODO()).Else(op).Then(op)
|
kv.Txn(context.TODO()).Else(op).Then(op)
|
||||||
},
|
},
|
||||||
|
|
||||||
err: "cannot call Then after Else!",
|
err: "cannot call Then after Else!",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
f: func() {
|
f: func(errc chan string) {
|
||||||
defer df()
|
defer df(errc)
|
||||||
kv.Txn(context.TODO()).Else(op).Else(op)
|
kv.Txn(context.TODO()).Else(op).Else(op)
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -93,7 +92,8 @@ func TestTxnPanics(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
go tt.f()
|
errc := make(chan string, 1)
|
||||||
|
go tt.f(errc)
|
||||||
select {
|
select {
|
||||||
case err := <-errc:
|
case err := <-errc:
|
||||||
if err != tt.err {
|
if err != tt.err {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user