-
Notifications
You must be signed in to change notification settings - Fork 980
/
Copy pathsaga_barrier_redis_test.go
48 lines (42 loc) · 1.54 KB
/
saga_barrier_redis_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright (c) 2021 yedf. All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/
package test
import (
"testing"
"github.com/dtm-labs/dtm/client/dtmcli"
"github.com/dtm-labs/dtm/client/dtmcli/dtmimp"
"github.com/dtm-labs/dtm/test/busi"
"github.com/stretchr/testify/assert"
)
func TestSagaBarrierRedisNormal(t *testing.T) {
busi.SetRedisBothAccount(100, 100)
before := getBeforeBalances("redis")
saga := genSagaBarrierRedis(dtmimp.GetFuncName())
err := saga.Submit()
assert.Nil(t, err)
waitTransProcessed(saga.Gid)
assert.Equal(t, []string{StatusPrepared, StatusSucceed, StatusPrepared, StatusSucceed}, getBranchesStatus(saga.Gid))
assert.Equal(t, StatusSucceed, getTransStatus(saga.Gid))
assertNotSameBalance(t, before, "redis")
}
func TestSagaBarrierRedisRollback(t *testing.T) {
busi.SetRedisBothAccount(20, 20)
before := getBeforeBalances("redis")
saga := genSagaBarrierRedis(dtmimp.GetFuncName())
err := saga.Submit()
assert.Nil(t, err)
waitTransProcessed(saga.Gid)
assert.Equal(t, StatusFailed, getTransStatus(saga.Gid))
assert.Equal(t, []string{StatusSucceed, StatusSucceed, StatusSucceed, StatusFailed}, getBranchesStatus(saga.Gid))
assertSameBalance(t, before, "redis")
}
func genSagaBarrierRedis(gid string) *dtmcli.Saga {
req := busi.GenReqHTTP(30, false, false)
req.Store = "redis"
return dtmcli.NewSaga(DtmServer, gid).
Add(Busi+"/SagaRedisTransIn", Busi+"/SagaRedisTransInCom", req).
Add(Busi+"/SagaRedisTransOut", Busi+"/SagaRedisTransOutCom", req)
}