-
Notifications
You must be signed in to change notification settings - Fork 980
/
Copy pathsaga_barrier_mongo_test.go
48 lines (42 loc) · 1.55 KB
/
saga_barrier_mongo_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 TestSagaBarrierMongoNormal(t *testing.T) {
MaySkipMongo(t)
before := getBeforeBalances("mongo")
saga := genSagaBarrierMongo(dtmimp.GetFuncName(), false)
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, "mongo")
}
func TestSagaBarrierMongoRollback(t *testing.T) {
MaySkipMongo(t)
before := getBeforeBalances("mongo")
saga := genSagaBarrierMongo(dtmimp.GetFuncName(), true)
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, "mongo")
}
func genSagaBarrierMongo(gid string, transInFailed bool) *dtmcli.Saga {
req := busi.GenReqHTTP(30, false, transInFailed)
req.Store = "mongo"
return dtmcli.NewSaga(DtmServer, gid).
Add(Busi+"/SagaMongoTransOut", Busi+"/SagaMongoTransOutCom", req).
Add(Busi+"/SagaMongoTransIn", Busi+"/SagaMongoTransInCom", req)
}