Skip to content

Commit d16c35e

Browse files
test: separate SSL server and client check
Current SSL tests are as follows. We start a Tarantool server with default helpers. "ok" tests are successful if everything had started, "fail" tests are successful if ping check had failed (aka we failed to connect). This is a dangerous approach, since "server had failed to start" here is indistinguishable from "client cannot connect". Moreover, because of it each tnt_fail test runs for 5 seconds (10 retry attempts * 500 ms retry wait), which is frustrating. After this patch, there is a separate check for a server start and for a client success or fail.
1 parent cccc461 commit d16c35e

File tree

1 file changed

+35
-9
lines changed

1 file changed

+35
-9
lines changed

ssl_test.go

+35-9
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func createClientServerSslOk(t testing.TB, serverOpts,
9494
return l, c, msgs, errs
9595
}
9696

97-
func serverTnt(serverOpts, clientOpts SslOpts, auth Auth) (test_helpers.TarantoolInstance, error) {
97+
func serverTnt(serverOpts SslOpts, auth Auth) (test_helpers.TarantoolInstance, error) {
9898
listen := tntHost + "?transport=ssl&"
9999

100100
key := serverOpts.KeyFile
@@ -126,7 +126,7 @@ func serverTnt(serverOpts, clientOpts SslOpts, auth Auth) (test_helpers.Tarantoo
126126
SslCertsDir: "testdata",
127127
ClientServer: tntHost,
128128
ClientTransport: "ssl",
129-
ClientSsl: clientOpts,
129+
ClientSsl: serverOpts,
130130
User: "test",
131131
Pass: "test",
132132
WaitStart: 100 * time.Millisecond,
@@ -139,6 +139,23 @@ func serverTntStop(inst test_helpers.TarantoolInstance) {
139139
test_helpers.StopTarantoolWithCleanup(inst)
140140
}
141141

142+
func checkTntConn(clientOpts SslOpts) error {
143+
conn, err := Connect(tntHost, Opts{
144+
Auth: AutoAuth,
145+
Timeout: 500 * time.Millisecond,
146+
User: "test",
147+
Pass: "test",
148+
SkipSchema: true,
149+
Transport: "ssl",
150+
Ssl: clientOpts,
151+
})
152+
if err != nil {
153+
return err
154+
}
155+
conn.Close()
156+
return nil
157+
}
158+
142159
func assertConnectionSslFail(t testing.TB, serverOpts, clientOpts SslOpts) {
143160
t.Helper()
144161

@@ -171,9 +188,13 @@ func assertConnectionSslOk(t testing.TB, serverOpts, clientOpts SslOpts) {
171188
func assertConnectionTntFail(t testing.TB, serverOpts, clientOpts SslOpts) {
172189
t.Helper()
173190

174-
inst, err := serverTnt(serverOpts, clientOpts, AutoAuth)
175-
serverTntStop(inst)
191+
inst, err := serverTnt(serverOpts, AutoAuth)
192+
if err != nil {
193+
t.Errorf("An unexpected server error %q", err.Error())
194+
}
195+
defer serverTntStop(inst)
176196

197+
err = checkTntConn(clientOpts)
177198
if err == nil {
178199
t.Errorf("An unexpected connection to the server")
179200
}
@@ -182,12 +203,16 @@ func assertConnectionTntFail(t testing.TB, serverOpts, clientOpts SslOpts) {
182203
func assertConnectionTntOk(t testing.TB, serverOpts, clientOpts SslOpts) {
183204
t.Helper()
184205

185-
inst, err := serverTnt(serverOpts, clientOpts, AutoAuth)
186-
serverTntStop(inst)
187-
206+
inst, err := serverTnt(serverOpts, AutoAuth)
188207
if err != nil {
189208
t.Errorf("An unexpected server error %q", err.Error())
190209
}
210+
defer serverTntStop(inst)
211+
212+
err = checkTntConn(clientOpts)
213+
if err != nil {
214+
t.Errorf("An unexpected connection error %q", err.Error())
215+
}
191216
}
192217

193218
type test struct {
@@ -470,11 +495,12 @@ func TestOpts_PapSha256Auth(t *testing.T) {
470495
KeyFile: "testdata/localhost.key",
471496
CertFile: "testdata/localhost.crt",
472497
}
473-
inst, err := serverTnt(sslOpts, sslOpts, PapSha256Auth)
474-
defer serverTntStop(inst)
498+
499+
inst, err := serverTnt(sslOpts, PapSha256Auth)
475500
if err != nil {
476501
t.Errorf("An unexpected server error: %s", err)
477502
}
503+
defer serverTntStop(inst)
478504

479505
clientOpts := opts
480506
clientOpts.Transport = "ssl"

0 commit comments

Comments
 (0)