@@ -33,6 +33,14 @@ type StartOpts struct {
33
33
// InitScript is a Lua script for tarantool to run on start.
34
34
InitScript string
35
35
36
+ // ConfigFile is a path to a configuration file for a Tarantool instance.
37
+ // Required in pair with InstanceName.
38
+ ConfigFile string
39
+
40
+ // InstanceName is a name of an instance to run.
41
+ // Required in pair with ConfigFile.
42
+ InstanceName string
43
+
36
44
// Listen is box.cfg listen parameter for tarantool.
37
45
// Use this address to connect to tarantool after configuration.
38
46
// https://www.tarantool.io/en/doc/latest/reference/configuration/#cfg-basic-listen
@@ -77,6 +85,32 @@ type TarantoolInstance struct {
77
85
78
86
// Dialer to check that connection established.
79
87
Dialer tarantool.Dialer
88
+
89
+ done chan error
90
+ is_done bool
91
+ result error
92
+ }
93
+
94
+ // Status checks if Tarantool instance is still running.
95
+ // Return true if it is running, false if it is not.
96
+ // If instance was exit and error is nil - process completed success with zero status code.
97
+ func (t * TarantoolInstance ) Status () (bool , error ) {
98
+ if t .is_done {
99
+ return false , t .result
100
+ }
101
+
102
+ select {
103
+ case t .result = <- t .done :
104
+ t .is_done = true
105
+ return false , t .result
106
+ default :
107
+ return true , nil
108
+ }
109
+ }
110
+
111
+ func (t * TarantoolInstance ) checkDone () {
112
+ t .done = make (chan error , 1 )
113
+ t .done <- t .Cmd .Wait ()
80
114
}
81
115
82
116
func isReady (dialer tarantool.Dialer , opts * tarantool.Opts ) error {
@@ -108,7 +142,7 @@ var (
108
142
)
109
143
110
144
func init () {
111
- tarantoolVersionRegexp = regexp .MustCompile (`Tarantool (?: Enterprise )?(\d+)\.(\d+)\.(\d+).*` )
145
+ tarantoolVersionRegexp = regexp .MustCompile (`Tarantool (Enterprise )?(\d+)\.(\d+)\.(\d+).*` )
112
146
}
113
147
114
148
// atoiUint64 parses string to uint64.
@@ -145,15 +179,15 @@ func IsTarantoolVersionLess(majorMin uint64, minorMin uint64, patchMin uint64) (
145
179
return true , fmt .Errorf ("failed to parse output %q" , out )
146
180
}
147
181
148
- if major , err = atoiUint64 (parsed [1 ]); err != nil {
182
+ if major , err = atoiUint64 (parsed [2 ]); err != nil {
149
183
return true , fmt .Errorf ("failed to parse major from output %q: %w" , out , err )
150
184
}
151
185
152
- if minor , err = atoiUint64 (parsed [2 ]); err != nil {
186
+ if minor , err = atoiUint64 (parsed [3 ]); err != nil {
153
187
return true , fmt .Errorf ("failed to parse minor from output %q: %w" , out , err )
154
188
}
155
189
156
- if patch , err = atoiUint64 (parsed [3 ]); err != nil {
190
+ if patch , err = atoiUint64 (parsed [4 ]); err != nil {
157
191
return true , fmt .Errorf ("failed to parse patch from output %q: %w" , out , err )
158
192
}
159
193
@@ -166,6 +200,21 @@ func IsTarantoolVersionLess(majorMin uint64, minorMin uint64, patchMin uint64) (
166
200
}
167
201
}
168
202
203
+ // IsTarantoolEE checks if Tarantool is Enterprise edition.
204
+ func IsTarantoolEE () (bool , error ) {
205
+ out , err := exec .Command (getTarantoolExec (), "--version" ).Output ()
206
+ if err != nil {
207
+ return true , err
208
+ }
209
+
210
+ parsed := tarantoolVersionRegexp .FindStringSubmatch (string (out ))
211
+ if parsed == nil {
212
+ return true , fmt .Errorf ("failed to parse output %q" , out )
213
+ }
214
+
215
+ return parsed [1 ] != "" , nil
216
+ }
217
+
169
218
// RestartTarantool restarts a tarantool instance for tests
170
219
// with specifies parameters (refer to StartOpts)
171
220
// which were specified in inst parameter.
@@ -211,6 +260,7 @@ func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
211
260
}
212
261
213
262
inst .Cmd = exec .Command (getTarantoolExec (), startOpts .InitScript )
263
+ inst .Cmd .Dir = startOpts .WorkDir
214
264
215
265
inst .Cmd .Env = append (
216
266
os .Environ (),
@@ -219,6 +269,11 @@ func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
219
269
fmt .Sprintf ("TEST_TNT_MEMTX_USE_MVCC_ENGINE=%t" , startOpts .MemtxUseMvccEngine ),
220
270
fmt .Sprintf ("TEST_TNT_AUTH_TYPE=%s" , startOpts .Auth ),
221
271
)
272
+ if startOpts .ConfigFile != "" && startOpts .InstanceName != "" {
273
+ inst .Cmd .Env = append (inst .Cmd .Env , fmt .Sprintf ("TT_CONFIG=%s" , startOpts .ConfigFile ))
274
+ inst .Cmd .Env = append (inst .Cmd .Env ,
275
+ fmt .Sprintf ("TT_INSTANCE_NAME=%s" , startOpts .InstanceName ))
276
+ }
222
277
223
278
// Copy SSL certificates.
224
279
if startOpts .SslCertsDir != "" {
@@ -242,6 +297,8 @@ func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
242
297
// see https://github.com/tarantool/go-tarantool/issues/136
243
298
time .Sleep (startOpts .WaitStart )
244
299
300
+ go inst .checkDone ()
301
+
245
302
opts := tarantool.Opts {
246
303
Timeout : 500 * time .Millisecond ,
247
304
SkipSchema : true ,
@@ -261,7 +318,17 @@ func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
261
318
}
262
319
}
263
320
264
- return inst , err
321
+ if err != nil {
322
+ StopTarantool (inst )
323
+ return TarantoolInstance {}, fmt .Errorf ("failed to connect Tarantool: %w" , err )
324
+ }
325
+
326
+ working , err := inst .Status ()
327
+ if ! working || err != nil {
328
+ StopTarantool (inst )
329
+ return TarantoolInstance {}, fmt .Errorf ("unexpected terminated Tarantool: %w" , err )
330
+ }
331
+ return inst , nil
265
332
}
266
333
267
334
// StopTarantool stops a tarantool instance started
0 commit comments