@@ -3,14 +3,13 @@ package regtest
3
3
import (
4
4
"bufio"
5
5
"encoding/json"
6
- "fmt"
7
6
"io/ioutil"
8
7
"os"
9
8
"path/filepath"
10
- "sort"
11
9
"strings"
12
10
13
11
"github.com/signal18/replication-manager/cluster"
12
+ "github.com/signal18/replication-manager/utils/misc"
14
13
)
15
14
16
15
var tests = []string {
@@ -78,7 +77,7 @@ func (regtest *RegTest) SaveTestsFromResult(cl *cluster.Cluster, result map[stri
78
77
return nil
79
78
}
80
79
81
- func (regtest * RegTest ) CreateTestsFromShare (cl * cluster.Cluster ) error {
80
+ func (regtest * RegTest ) CreateTestsFromShare (cl * cluster.Cluster ) map [ string ]cluster. Test {
82
81
Path := cl .GetShareDir () + "/tests/"
83
82
var allTests = map [string ]cluster.Test {}
84
83
err := filepath .Walk (Path , func (path string , info os.FileInfo , err error ) error {
@@ -98,7 +97,7 @@ func (regtest *RegTest) CreateTestsFromShare(cl *cluster.Cluster) error {
98
97
var test cluster.Test
99
98
scenario := scanner .Text ()
100
99
test .Name = scenario
101
- test .ConfigFile = path + "/replication-manager .toml"
100
+ test .ConfigFile = filepath . Dir ( path ) + "/config .toml"
102
101
allTests [path + "/" + scenario ] = test
103
102
tests = append (tests , scenario )
104
103
}
@@ -108,20 +107,32 @@ func (regtest *RegTest) CreateTestsFromShare(cl *cluster.Cluster) error {
108
107
return err
109
108
}
110
109
111
- fmt .Printf ("dir: %s name: %s\n " , strings .Join (tests , "," ), path )
110
+ // fmt.Printf("dir: %s name: %s\n", strings.Join(tests, ","), path)
112
111
}
113
112
}
114
113
115
114
return err
116
115
})
117
116
if err != nil {
118
- return err
117
+ return allTests
119
118
}
120
119
saveJson , _ := json .MarshalIndent (allTests , "" , "\t " )
121
120
errmarshall := ioutil .WriteFile (cl .Conf .WorkingDir + "/" + cl .Name + "/tests.json" , saveJson , 0644 )
122
121
if errmarshall != nil {
123
- return errmarshall
122
+ return allTests
123
+ }
124
+ return allTests
125
+ }
126
+
127
+ func (regtest * RegTest ) CopyConfig (cl * cluster.Cluster , test cluster.Test ) error {
128
+ srcFile := test .ConfigFile
129
+ // The scenario run on the local cluster and does need a special config
130
+ if srcFile == "" {
131
+ return nil
124
132
}
133
+ dstFile := cl .GetIncludeDir () + "/" + filepath .Base (srcFile )
134
+ cl .LogPrintf ("INFO" , "Copy from %s to %s" , srcFile , dstFile )
135
+ misc .CopyFile (srcFile , dstFile )
125
136
return nil
126
137
}
127
138
@@ -139,199 +150,22 @@ func (regtest *RegTest) GetTestsFromScenarios(cl *cluster.Cluster, scenarios []s
139
150
return allTests
140
151
}
141
152
142
- // RunAllTests can run
143
- // - Single scenario on the monitored cluster
144
- // - All scenarios on the monitored cluster
145
- // - All found scenarios under a given path in the test suite directory
146
- // play scenarios listed in files .todo with a config replication-manager.toml found in same directory
147
- //
148
- // Returns
149
- // - A map of cluster.Test executed
150
- // - Saved this map in the cluster datadir under tests.json file acumulate multiple run
151
- //
152
- // Workflow
153
- // - Build a map of cluster.Test based on parmater type
154
- // - Loop over the map
155
- //
156
- // Call the test that
157
- // - Copy the config in include directory when given
158
- // - Relaod the config
159
- // - Provision the cluster
160
- // - Play the scenario
161
- // - Unprovision the cluster
162
-
163
- func (regtest * RegTest ) RunAllTests (cl * cluster.Cluster , testExp string , path string ) []cluster.Test {
153
+ func (regtest * RegTest ) GetTestsFromPath (cl * cluster.Cluster , tests map [string ]cluster.Test , path string ) map [string ]cluster.Test {
164
154
var allTests = map [string ]cluster.Test {}
165
- pathdefault := cl .GetShareDir () + "/" + cl .GetOrchestrator () + "/config/masterslave/mariadb/without_traffic/10.5/x2/semisync"
166
- if path == "" {
167
- path = pathdefault
168
- }
169
-
170
- if testExp == "SUITE" {
171
- regtest .CreateTestsFromShare (cl )
172
- } else if testExp == "ALL" {
173
- allTests = regtest .GetTestsFromScenarios (cl , regtest .GetTests ())
174
- } else {
175
- allTests = regtest .GetTestsFromScenarios (cl , strings .Split (testExp , "," ))
176
- }
177
-
178
- for key , test := range allTests {
155
+ for key , thisTest := range tests {
156
+ var test cluster.Test
157
+ cl .LogPrintf ("TEST" , "filter %s %s" , key , path )
179
158
180
- var res bool
181
- cl .LogPrintf ("TEST : %s" , test .Name )
159
+ if strings .Contains (key , path ) {
182
160
183
- test .ConfigFile = cl .GetConf ().ConfigFile
184
- if ! cl .InitTestCluster (test .ConfigFile , & test ) {
185
- test .Result = "ERR"
186
- } else {
187
- if test .Name == "testFailoverManual" {
188
- res = testFailoverSemisyncAutoRejoinSafeMSMXMS (cl , test .ConfigFile , & test )
189
- }
190
- if test .Name == "testFailoverSemisyncAutoRejoinSafeMSMXMS" {
191
- res = testFailoverSemisyncAutoRejoinSafeMSMXMS (cl , test .ConfigFile , & test )
192
- }
193
- if test .Name == "testFailoverSemisyncAutoRejoinSafeMSXMSM" {
194
- res = testFailoverSemisyncAutoRejoinSafeMSXMSM (cl , test .ConfigFile , & test )
195
- }
196
- if test .Name == "testFailoverSemisyncAutoRejoinSafeMSMXXXRMXMS" {
197
- res = testFailoverSemisyncAutoRejoinSafeMSMXXXRMXMS (cl , test .ConfigFile , & test )
198
- }
199
- if test .Name == "testFailoverSemisyncAutoRejoinSafeMSMXXXRXSMS" {
200
- res = testFailoverSemisyncAutoRejoinSafeMSMXXXRXSMS (cl , test .ConfigFile , & test )
201
- }
202
- if test .Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXMS" {
203
- res = testFailoverSemisyncAutoRejoinUnsafeMSMXMS (cl , test .ConfigFile , & test )
204
- }
205
- if test .Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXXXMXMS" {
206
- res = testFailoverSemisyncAutoRejoinUnsafeMSMXXXMXMS (cl , test .ConfigFile , & test )
207
- }
208
- if test .Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXXXXMSM" {
209
- res = testFailoverSemisyncAutoRejoinUnsafeMSMXXXXMSM (cl , test .ConfigFile , & test )
210
- }
211
- if test .Name == "testFailoverSemisyncAutoRejoinUnsafeMSXMSM" {
212
- res = testFailoverSemisyncAutoRejoinUnsafeMSXMSM (cl , test .ConfigFile , & test )
213
- }
214
- if test .Name == "testFailoverSemisyncAutoRejoinUnsafeMSXMXXMXMS" {
215
- res = testFailoverSemisyncAutoRejoinUnsafeMSXMXXMXMS (cl , test .ConfigFile , & test )
216
- }
217
- if test .Name == "testFailoverSemisyncAutoRejoinUnsafeMSXMXXXMSM" {
218
- res = testFailoverSemisyncAutoRejoinUnsafeMSXMXXXMSM (cl , test .ConfigFile , & test )
219
- }
220
- if test .Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXXXRMXMS" {
221
- res = testFailoverSemisyncAutoRejoinUnsafeMSMXXXRMXMS (cl , test .ConfigFile , & test )
222
- }
223
- if test .Name == "testFailoverSemisyncAutoRejoinUnsafeMSMXXXRXMSM" {
224
- res = testFailoverSemisyncAutoRejoinUnsafeMSMXXXRXMSM (cl , test .ConfigFile , & test )
225
- }
226
- if test .Name == "testFailoverAssyncAutoRejoinNoGtid" {
227
- res = testFailoverAssyncAutoRejoinNoGtid (cl , test .ConfigFile , & test )
228
- }
229
- if test .Name == "testFailoverAssyncAutoRejoinRelay" {
230
- res = testFailoverAssyncAutoRejoinRelay (cl , test .ConfigFile , & test )
231
- }
232
- if test .Name == "testFailoverSemisyncAutoRejoinMSSXMSXXMSXMSSM" {
233
- res = testFailoverSemisyncAutoRejoinMSSXMSXXMSXMSSM (cl , test .ConfigFile , & test )
234
- }
235
- if test .Name == "testFailoverSemisyncAutoRejoinMSSXMSXXMXSMSSM" {
236
- res = testFailoverSemisyncAutoRejoinMSSXMSXXMXSMSSM (cl , test .ConfigFile , & test )
237
- }
238
- if test .Name == "testFailoverSemisyncSlavekilledAutoRejoin" {
239
- res = testFailoverSemisyncSlavekilledAutoRejoin (cl , test .ConfigFile , & test )
240
- }
241
- if test .Name == "testFailoverSemisyncAutoRejoinFlashback" {
242
- res = testFailoverSemisyncAutoRejoinFlashback (cl , test .ConfigFile , & test )
243
- }
244
- if test .Name == "testFailoverAssyncAutoRejoinFlashback" {
245
- res = testFailoverAssyncAutoRejoinFlashback (cl , test .ConfigFile , & test )
246
- }
247
- if test .Name == "testFailoverAssyncAutoRejoinNowrites" {
248
- res = testFailoverAssyncAutoRejoinNowrites (cl , test .ConfigFile , & test )
249
- }
250
- if test .Name == "testFailoverAssyncAutoRejoinDump" {
251
- res = testFailoverAssyncAutoRejoinDump (cl , test .ConfigFile , & test )
252
- }
253
- if test .Name == "testSwitchoverAllSlavesDelayMultimasterNoRplChecksNoSemiSync" {
254
- res = testSwitchoverAllSlavesDelayMultimasterNoRplChecksNoSemiSync (cl , test .ConfigFile , & test )
255
- }
256
- if test .Name == "testSwitchoverLongTransactionNoRplCheckNoSemiSync" {
257
- res = testSwitchoverLongTransactionNoRplCheckNoSemiSync (cl , test .ConfigFile , & test )
258
- }
259
- if test .Name == "testSwitchoverLongTrxWithoutCommitNoRplCheckNoSemiSync" {
260
- res = testSwitchoverLongTrxWithoutCommitNoRplCheckNoSemiSync (cl , test .ConfigFile , & test )
261
- }
262
- if test .Name == "testSwitchoverLongQueryNoRplCheckNoSemiSync" {
263
- res = testSwitchoverLongQueryNoRplCheckNoSemiSync (cl , test .ConfigFile , & test )
264
- }
265
- if test .Name == "testSwitchoverNoReadOnlyNoRplCheck" {
266
- res = testSwitchoverNoReadOnlyNoRplCheck (cl , test .ConfigFile , & test )
267
- }
268
- if test .Name == "testSwitchoverReadOnlyNoRplCheck" {
269
- res = testSwitchoverReadOnlyNoRplCheck (cl , test .ConfigFile , & test )
270
- }
271
- if test .Name == "testSwitchover2TimesReplicationOkNoSemiSyncNoRplCheck" {
272
- res = testSwitchover2TimesReplicationOkNoSemiSyncNoRplCheck (cl , test .ConfigFile , & test )
273
- }
274
- if test .Name == "testSwitchover2TimesReplicationOkSemiSyncNoRplCheck" {
275
- res = testSwitchover2TimesReplicationOkSemiSyncNoRplCheck (cl , test .ConfigFile , & test )
276
- }
277
- if test .Name == "testSwitchoverBackPreferedMasterNoRplCheckSemiSync" {
278
- res = testSwitchoverBackPreferedMasterNoRplCheckSemiSync (cl , test .ConfigFile , & test )
279
- }
280
- if test .Name == "testSwitchoverAllSlavesStopRplCheckNoSemiSync" {
281
- res = testSwitchoverAllSlavesStopRplCheckNoSemiSync (cl , test .ConfigFile , & test )
282
- }
283
- if test .Name == "testSwitchoverAllSlavesStopNoSemiSyncNoRplCheck" {
284
- res = testSwitchoverAllSlavesStopNoSemiSyncNoRplCheck (cl , test .ConfigFile , & test )
285
- }
286
- if test .Name == "testSwitchoverAllSlavesDelayRplCheckNoSemiSync" {
287
- res = testSwitchoverAllSlavesDelayRplCheckNoSemiSync (cl , test .ConfigFile , & test )
288
- }
289
- if test .Name == "testSwitchoverAllSlavesDelayNoRplChecksNoSemiSync" {
290
- res = testSwitchoverAllSlavesDelayNoRplChecksNoSemiSync (cl , test .ConfigFile , & test )
291
- }
292
- if test .Name == "testSlaReplAllSlavesStopNoSemiSync" {
293
- res = testSlaReplAllSlavesStopNoSemiSync (cl , test .ConfigFile , & test )
294
- }
295
- if test .Name == "testSlaReplAllSlavesDelayNoSemiSync" {
296
- res = testSlaReplAllSlavesDelayNoSemiSync (cl , test .ConfigFile , & test )
297
- }
298
- if test .Name == "testFailoverNoRplChecksNoSemiSync" {
299
- res = testFailoverNoRplChecksNoSemiSync (cl , test .ConfigFile , & test )
300
- }
301
- if test .Name == "testFailoverAllSlavesDelayNoRplChecksNoSemiSync" {
302
- res = testFailoverAllSlavesDelayNoRplChecksNoSemiSync (cl , test .ConfigFile , & test )
303
- }
304
- if test .Name == "testFailoverAllSlavesDelayRplChecksNoSemiSync" {
305
- res = testFailoverAllSlavesDelayRplChecksNoSemiSync (cl , test .ConfigFile , & test )
306
- }
307
- if test .Name == "testFailoverNumberFailureLimitReach" {
308
- res = testFailoverNumberFailureLimitReach (cl , test .ConfigFile , & test )
309
- }
310
- if test .Name == "testFailoverTimeNotReach" {
311
- res = testFailoverTimeNotReach (cl , test .ConfigFile , & test )
312
- }
313
- test .Result = regtest .getTestResultLabel (res )
314
- cl .CloseTestCluster (test .ConfigFile , & test )
161
+ test = thisTest
315
162
allTests [key ] = test
316
163
}
317
- } //end loop on all tests
318
-
319
- vals := make ([]cluster.Test , 0 , len (allTests ))
320
- keys := make ([]string , 0 , len (allTests ))
321
- for key , val := range allTests {
322
- keys = append (keys , key )
323
- vals = append (vals , val )
324
- }
325
- sort .Strings (keys )
326
- for _ , v := range keys {
327
- cl .LogPrintf ("TEST" , "Result %s -> %s" , strings .Trim (v + strings .Repeat (" " , 60 - len (v )), "test" ), allTests [v ].Result )
328
164
}
329
- cl .CleanAll = false
330
- regtest .SaveTestsFromResult (cl , allTests )
331
- return vals
165
+ return allTests
332
166
}
333
167
334
- func (regtest * RegTest ) getTestResultLabel (res bool ) string {
168
+ func (regtest * RegTest ) GetTestResultLabel (res bool ) string {
335
169
if res == false {
336
170
return "FAIL"
337
171
} else {
0 commit comments