@@ -33,6 +33,14 @@ type StartOpts struct {
3333 // InitScript is a Lua script for tarantool to run on start.
3434 InitScript string
3535
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+
3644 // Listen is box.cfg listen parameter for tarantool.
3745 // Use this address to connect to tarantool after configuration.
3846 // https://www.tarantool.io/en/doc/latest/reference/configuration/#cfg-basic-listen
@@ -77,6 +85,25 @@ type TarantoolInstance struct {
7785
7886 // Dialer to check that connection established.
7987 Dialer tarantool.Dialer
88+
89+ done chan error
90+ }
91+
92+ // WorkStatus checks if Tarantool instance is still running.
93+ // Return true if it is running, false if it is not.
94+ // If instance was exit and error is nil - process completed success with zero status code.
95+ func (t * TarantoolInstance ) WorkStatus () (bool , error ) {
96+ select {
97+ case err := <- t .done :
98+ return false , err
99+ default :
100+ return true , nil
101+ }
102+ }
103+
104+ func (t * TarantoolInstance ) checkDone () {
105+ t .done = make (chan error , 1 )
106+ t .done <- t .Cmd .Wait ()
80107}
81108
82109func isReady (dialer tarantool.Dialer , opts * tarantool.Opts ) error {
@@ -108,7 +135,7 @@ var (
108135)
109136
110137func init () {
111- tarantoolVersionRegexp = regexp .MustCompile (`Tarantool (?: Enterprise )?(\d+)\.(\d+)\.(\d+).*` )
138+ tarantoolVersionRegexp = regexp .MustCompile (`Tarantool (Enterprise )?(\d+)\.(\d+)\.(\d+).*` )
112139}
113140
114141// atoiUint64 parses string to uint64.
@@ -145,15 +172,15 @@ func IsTarantoolVersionLess(majorMin uint64, minorMin uint64, patchMin uint64) (
145172 return true , fmt .Errorf ("failed to parse output %q" , out )
146173 }
147174
148- if major , err = atoiUint64 (parsed [1 ]); err != nil {
175+ if major , err = atoiUint64 (parsed [2 ]); err != nil {
149176 return true , fmt .Errorf ("failed to parse major from output %q: %w" , out , err )
150177 }
151178
152- if minor , err = atoiUint64 (parsed [2 ]); err != nil {
179+ if minor , err = atoiUint64 (parsed [3 ]); err != nil {
153180 return true , fmt .Errorf ("failed to parse minor from output %q: %w" , out , err )
154181 }
155182
156- if patch , err = atoiUint64 (parsed [3 ]); err != nil {
183+ if patch , err = atoiUint64 (parsed [4 ]); err != nil {
157184 return true , fmt .Errorf ("failed to parse patch from output %q: %w" , out , err )
158185 }
159186
@@ -166,6 +193,21 @@ func IsTarantoolVersionLess(majorMin uint64, minorMin uint64, patchMin uint64) (
166193 }
167194}
168195
196+ // IsTarantoolEE checks if Tarantool is Enterprise edition.
197+ func IsTarantoolEE () (bool , error ) {
198+ out , err := exec .Command (getTarantoolExec (), "--version" ).Output ()
199+ if err != nil {
200+ return true , err
201+ }
202+
203+ parsed := tarantoolVersionRegexp .FindStringSubmatch (string (out ))
204+ if parsed == nil {
205+ return true , fmt .Errorf ("failed to parse output %q" , out )
206+ }
207+
208+ return parsed [1 ] != "" , nil
209+ }
210+
169211// RestartTarantool restarts a tarantool instance for tests
170212// with specifies parameters (refer to StartOpts)
171213// which were specified in inst parameter.
@@ -211,6 +253,7 @@ func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
211253 }
212254
213255 inst .Cmd = exec .Command (getTarantoolExec (), startOpts .InitScript )
256+ inst .Cmd .Dir = startOpts .WorkDir
214257
215258 inst .Cmd .Env = append (
216259 os .Environ (),
@@ -219,6 +262,11 @@ func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
219262 fmt .Sprintf ("TEST_TNT_MEMTX_USE_MVCC_ENGINE=%t" , startOpts .MemtxUseMvccEngine ),
220263 fmt .Sprintf ("TEST_TNT_AUTH_TYPE=%s" , startOpts .Auth ),
221264 )
265+ if startOpts .ConfigFile != "" && startOpts .InstanceName != "" {
266+ inst .Cmd .Env = append (inst .Cmd .Env , fmt .Sprintf ("TT_CONFIG=%s" , startOpts .ConfigFile ))
267+ inst .Cmd .Env = append (inst .Cmd .Env ,
268+ fmt .Sprintf ("TT_INSTANCE_NAME=%s" , startOpts .InstanceName ))
269+ }
222270
223271 // Copy SSL certificates.
224272 if startOpts .SslCertsDir != "" {
@@ -242,6 +290,8 @@ func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
242290 // see https://github.com/tarantool/go-tarantool/issues/136
243291 time .Sleep (startOpts .WaitStart )
244292
293+ go inst .checkDone ()
294+
245295 opts := tarantool.Opts {
246296 Timeout : 500 * time .Millisecond ,
247297 SkipSchema : true ,
@@ -261,6 +311,16 @@ func StartTarantool(startOpts StartOpts) (TarantoolInstance, error) {
261311 }
262312 }
263313
314+ if err != nil {
315+ StopTarantool (inst )
316+ return TarantoolInstance {}, fmt .Errorf ("failed to connect Tarantool: %w" , err )
317+ }
318+
319+ working , err := inst .WorkStatus ()
320+ if ! working || err != nil {
321+ StopTarantool (inst )
322+ return TarantoolInstance {}, fmt .Errorf ("unexpected terminated Tarantool: %w" , err )
323+ }
264324 return inst , err
265325}
266326
0 commit comments