@@ -67,7 +67,7 @@ public async Task Execute_gPRC_Should_Succeed()
67
67
}
68
68
69
69
[ Fact ]
70
- public async Task Execute_DoAndHttpSuccess ( )
70
+ public async Task Execute_DoAndHttp_ShouldSuccess ( )
71
71
{
72
72
var provider = ITTestHelper . AddDtmGrpc ( ) ;
73
73
var workflowFactory = provider . GetRequiredService < IWorkflowFactory > ( ) ;
@@ -90,17 +90,25 @@ public async Task Execute_DoAndHttpSuccess()
90
90
return ( "my result"u8 . ToArray ( ) , null ) ;
91
91
} ) ;
92
92
93
- // 2. http1
93
+ // 2. http1, SAGA
94
94
HttpResponseMessage httpResult1 = await workflow . NewBranch ( ) . OnRollback ( async ( barrier ) =>
95
95
{
96
96
_testOutputHelper . WriteLine ( "4. http1 rollback" ) ;
97
+ await workflow . NewRequest ( ) . GetAsync ( "http://localhost:5006/test-http-ok1" ) ;
97
98
} ) . NewRequest ( ) . GetAsync ( "http://localhost:5006/test-http-ok1" ) ;
98
99
99
- // 3. http2
100
+ // 3. http2, TCC
100
101
HttpResponseMessage httpResult2 = await workflow . NewBranch ( ) . OnRollback ( async ( barrier ) =>
101
102
{
102
- _testOutputHelper . WriteLine ( "4. http2 rollback" ) ;
103
- } ) . NewRequest ( ) . GetAsync ( "http://localhost:5006/test-http-ok2" ) ;
103
+ _testOutputHelper . WriteLine ( "4. http2 cancel" ) ;
104
+
105
+ await workflow . NewRequest ( ) . GetAsync ( "http://localhost:5006/test-http-ok1" ) ;
106
+ } ) . OnCommit ( async ( barrier ) =>
107
+ {
108
+ _testOutputHelper . WriteLine ( "4. http2 commit" ) ;
109
+ // NOT must use workflow.NewRequest()
110
+ await workflow . NewRequest ( ) . GetAsync ( "http://localhost:5006/test-http-ok1" ) ;
111
+ } ) . NewRequest ( ) . GetAsync ( "http://localhost:5006/test-http-ok1" ) ;
104
112
105
113
await busiClient . TransOutAsync ( request ) ;
106
114
@@ -113,25 +121,40 @@ public async Task Execute_DoAndHttpSuccess()
113
121
DtmClient dtmClient = new DtmClient ( provider . GetRequiredService < IHttpClientFactory > ( ) , provider . GetRequiredService < IOptions < DtmOptions > > ( ) ) ;
114
122
TransGlobal trans ;
115
123
124
+ // BranchID Op Status
125
+ // 01 action succeed
126
+ // 02 action succeed
127
+ // 03 action succeed
128
+ // 03 commit succeed
116
129
// first
117
130
byte [ ] result = await workflowGlobalTransaction . Execute ( wfName1 , gid , Encoding . UTF8 . GetBytes ( JsonConvert . SerializeObject ( req ) ) ) ;
118
131
Assert . Equal ( "my result" , Encoding . UTF8 . GetString ( result ) ) ;
119
132
trans = await dtmClient . Query ( gid , CancellationToken . None ) ;
120
133
Assert . Equal ( "succeed" , trans . Transaction . Status ) ;
121
- Assert . Equal ( 3 , trans . Branches . Count ) ; // 1.Do 2.Http 3.Http
134
+ Assert . Equal ( 4 , trans . Branches . Count ) ; // 1.Do x1, 2.http, saga x1, 3.Http tcc x2
135
+ Assert . Equal ( "action" , trans . Branches [ 0 ] . Op ) ;
122
136
Assert . Equal ( "succeed" , trans . Branches [ 0 ] . Status ) ;
137
+ Assert . Equal ( "action" , trans . Branches [ 1 ] . Op ) ;
123
138
Assert . Equal ( "succeed" , trans . Branches [ 1 ] . Status ) ;
139
+ Assert . Equal ( "action" , trans . Branches [ 2 ] . Op ) ;
124
140
Assert . Equal ( "succeed" , trans . Branches [ 2 ] . Status ) ;
141
+ Assert . Equal ( "commit" , trans . Branches [ 3 ] . Op ) ;
142
+ Assert . Equal ( "succeed" , trans . Branches [ 3 ] . Status ) ;
125
143
126
144
// same gid again
127
145
result = await workflowGlobalTransaction . Execute ( wfName1 , gid , Encoding . UTF8 . GetBytes ( JsonConvert . SerializeObject ( req ) ) ) ;
128
146
Assert . Equal ( "my result" , Encoding . UTF8 . GetString ( result ) ) ;
129
147
trans = await dtmClient . Query ( gid , CancellationToken . None ) ;
130
148
Assert . Equal ( "succeed" , trans . Transaction . Status ) ;
131
- Assert . Equal ( 3 , trans . Branches . Count ) ; // 1.Do 2.Http 3.Http
149
+ Assert . Equal ( 4 , trans . Branches . Count ) ; // 1.Do x1, 2.http, saga x1, 3.Http tcc x2
150
+ Assert . Equal ( "action" , trans . Branches [ 0 ] . Op ) ;
132
151
Assert . Equal ( "succeed" , trans . Branches [ 0 ] . Status ) ;
152
+ Assert . Equal ( "action" , trans . Branches [ 1 ] . Op ) ;
133
153
Assert . Equal ( "succeed" , trans . Branches [ 1 ] . Status ) ;
154
+ Assert . Equal ( "action" , trans . Branches [ 2 ] . Op ) ;
134
155
Assert . Equal ( "succeed" , trans . Branches [ 2 ] . Status ) ;
156
+ Assert . Equal ( "commit" , trans . Branches [ 3 ] . Op ) ;
157
+ Assert . Equal ( "succeed" , trans . Branches [ 3 ] . Status ) ;
135
158
}
136
159
137
160
[ Fact ]
0 commit comments