Skip to content

Commit 095263e

Browse files
authored
Do not run forwarding test if user traffic extensions not present. (#210)
* Do not run forwarding test if user traffic extensions not present. * Use TLS 1.3 (opt in). * Some more waits and prettiness. * Fix test compilation.
1 parent 4407cf8 commit 095263e

File tree

2 files changed

+50
-41
lines changed

2 files changed

+50
-41
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ __test_go_test:
330330
-e TEST_MODE=$(TEST_MODE) \
331331
-e TEST_BACKUP_REMOTE_REPO=$(TEST_BACKUP_REMOTE_REPO) \
332332
-e TEST_BACKUP_REMOTE_CONFIG='$(TEST_BACKUP_REMOTE_CONFIG)' \
333+
-e GODEBUG=tls13=1 \
333334
-e CGO_ENABLED=0 \
334335
-w /usr/code/ \
335336
golang:$(GOVERSION) \
@@ -373,6 +374,7 @@ run-tests-cluster-failover:
373374
-v "${ROOTDIR}":/usr/code \
374375
-e TEST_ENDPOINTS=http://127.0.0.1:7001,http://127.0.0.1:7006,http://127.0.0.1:7011 \
375376
-e TEST_AUTHENTICATION=basic:root: \
377+
-e GODEBUG=tls13=1 \
376378
-w /usr/code/ \
377379
golang:$(GOVERSION) \
378380
go test -run ".*Failover.*" -tags failover $(TESTOPTIONS) $(REPOPATH)/test

test/server_statistics_test.go

Lines changed: 48 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ const (
8484
)
8585

8686
type limits struct {
87-
Received float64
88-
Sent float64
89-
RecCount int64
87+
Recv float64
88+
Sent float64
89+
RecvCount int64
9090
SentCount int64
9191
}
9292

9393

9494
// checkTrafficAtLeast compares stats before and after some operation and
9595
// checks that at least some amount of traffic has happened.
96-
func checkTrafficAtLeast(t *testing.T, statsBefore *driver.ServerStatistics, statsAfter *driver.ServerStatistics, which source, lim *limits) {
96+
func checkTrafficAtLeast(t *testing.T, statsBefore *driver.ServerStatistics, statsAfter *driver.ServerStatistics, which source, lim *limits, label string) {
9797
var before *driver.ClientStats
9898
var after *driver.ClientStats
9999
var name string
@@ -107,30 +107,30 @@ func checkTrafficAtLeast(t *testing.T, statsBefore *driver.ServerStatistics, sta
107107
name = "Client"
108108
}
109109
diff := after.BytesReceived.Sum - before.BytesReceived.Sum
110-
if diff < lim.Received {
111-
t.Errorf("Difference in %s.BytesReceived.Sum is too small (< %f): %f",
112-
name, lim.Received, diff)
110+
if diff < lim.Recv {
111+
t.Errorf("%s: Difference in %s.BytesReceived.Sum is too small (< %f): %f",
112+
label, name, lim.Recv, diff)
113113
}
114114
diff = after.BytesSent.Sum - before.BytesSent.Sum
115115
if diff < lim.Sent {
116-
t.Errorf("Difference in %s.BytesSent.Sum is too small (< %f): %f",
117-
name, lim.Sent, diff)
116+
t.Errorf("%s: Difference in %s.BytesSent.Sum is too small (< %f): %f",
117+
label, name, lim.Sent, diff)
118118
}
119119
intDiff := after.BytesReceived.Count - before.BytesReceived.Count
120-
if intDiff < lim.RecCount {
121-
t.Errorf("Difference in %s.BytesReceived.Count is too small (< %d): %d",
122-
name, lim.RecCount, intDiff)
120+
if intDiff < lim.RecvCount {
121+
t.Errorf("%s: Difference in %s.BytesReceived.Count is too small (< %d): %d",
122+
label, name, lim.RecvCount, intDiff)
123123
}
124124
intDiff = after.BytesSent.Count - before.BytesSent.Count
125125
if intDiff < lim.SentCount {
126-
t.Errorf("Difference in %s.BytesSent.Count is too small (< %d): %d",
127-
name, lim.SentCount, intDiff)
126+
t.Errorf("%s: Difference in %s.BytesSent.Count is too small (< %d): %d",
127+
label, name, lim.SentCount, intDiff)
128128
}
129129
}
130130

131131
// checkTrafficAtMost compares stats before and after some operation and
132132
// checks that at most some amount of traffic has happened.
133-
func checkTrafficAtMost(t *testing.T, statsBefore *driver.ServerStatistics, statsAfter *driver.ServerStatistics, which source, lim *limits) {
133+
func checkTrafficAtMost(t *testing.T, statsBefore *driver.ServerStatistics, statsAfter *driver.ServerStatistics, which source, lim *limits, label string) {
134134
var before *driver.ClientStats
135135
var after *driver.ClientStats
136136
var name string
@@ -144,24 +144,24 @@ func checkTrafficAtMost(t *testing.T, statsBefore *driver.ServerStatistics, stat
144144
name = "Client"
145145
}
146146
diff := after.BytesReceived.Sum - before.BytesReceived.Sum
147-
if diff > lim.Received {
148-
t.Errorf("Difference in %s.BytesReceived.Sum is too large (> %f): %f",
149-
name, lim.Received, diff)
147+
if diff > lim.Recv {
148+
t.Errorf("%s: Difference in %s.BytesReceived.Sum is too large (> %f): %f",
149+
label, name, lim.Recv, diff)
150150
}
151151
diff = after.BytesSent.Sum - before.BytesSent.Sum
152152
if diff > lim.Sent {
153-
t.Errorf("Difference in %s.BytesSent.Sum is too large (> %f): %f",
154-
name, lim.Sent, diff)
153+
t.Errorf("%s: Difference in %s.BytesSent.Sum is too large (> %f): %f",
154+
label, name, lim.Sent, diff)
155155
}
156156
intDiff := after.BytesReceived.Count - before.BytesReceived.Count
157-
if intDiff > lim.RecCount {
158-
t.Errorf("Difference in %s.BytesReceived.Count is too large (> %d): %d",
159-
name, lim.RecCount, intDiff)
157+
if intDiff > lim.RecvCount {
158+
t.Errorf("%s: Difference in %s.BytesReceived.Count is too large (> %d): %d",
159+
label, name, lim.RecvCount, intDiff)
160160
}
161161
intDiff = after.BytesSent.Count - before.BytesSent.Count
162162
if intDiff > lim.SentCount {
163-
t.Errorf("Difference in %s.BytesSent.Count is too large (> %d): %d",
164-
name, lim.SentCount, intDiff)
163+
t.Errorf("%s: Difference in %s.BytesSent.Count is too large (> %d): %d",
164+
label, name, lim.SentCount, intDiff)
165165
}
166166
}
167167

@@ -188,8 +188,8 @@ func TestServerStatisticsTraffic(t *testing.T) {
188188
}
189189

190190
checkTrafficAtLeast(t, &statsBefore, &statsAfter, all,
191-
&limits{Sent: 100000.0, Received: 40000.0,
192-
SentCount: 1000, RecCount: 1000});
191+
&limits{Sent: 100000.0, Recv: 40000.0,
192+
SentCount: 1000, RecvCount: 1000}, "Banana");
193193

194194
// Now check if user only stats are there and see if they should have increased:
195195
if statsBefore.ClientUser.BytesReceived.Counts != nil {
@@ -200,15 +200,15 @@ func TestServerStatisticsTraffic(t *testing.T) {
200200
// Traffic is superuser, so nothing should be counted in ClientUser,
201201
// not even the statistics calls.
202202
checkTrafficAtMost(t, &statsBefore, &statsAfter, user,
203-
&limits{Sent: 0.1, Received: 0.1,
204-
SentCount: 0, RecCount: 0});
203+
&limits{Sent: 0.1, Recv: 0.1,
204+
SentCount: 0, RecvCount: 0}, "Cherry");
205205
} else {
206206
t.Logf("Authentication %s is not jwt superuser, expecting to see user traffic...", auth)
207207
// Traffic is either unauthenticated or with password, so there should
208208
// be traffic in ClientUser
209209
checkTrafficAtLeast(t, &statsBefore, &statsAfter, user,
210-
&limits{Sent: 100000.0, Received: 40000.0,
211-
SentCount: 1000, RecCount: 1000});
210+
&limits{Sent: 100000.0, Recv: 40000.0,
211+
SentCount: 1000, RecvCount: 1000}, "Apple");
212212
}
213213
} else {
214214
t.Log("Skipping ClientUser tests for statistics, since API is not present.")
@@ -256,6 +256,8 @@ func TestServerStatisticsForwarding(t *testing.T) {
256256
ctx1 := driver.WithEndpoint(context.Background(), endpoints[0])
257257
ctx2 := driver.WithEndpoint(context.Background(), endpoints[1])
258258

259+
time.Sleep(time.Second) // wait for statistics to settle
260+
259261
statsBefore, err := c.Statistics(ctx2)
260262
if err != nil {
261263
t.Fatalf("Error in statistics call: %s", describe(err))
@@ -277,8 +279,12 @@ func TestServerStatisticsForwarding(t *testing.T) {
277279

278280
// No traffic on second coordinator (besides statistics calls):
279281
checkTrafficAtMost(t, &statsBefore, &statsAfter, all,
280-
&limits{Received: 400, Sent: 4000,
281-
RecCount: 2, SentCount: 2})
282+
&limits{Recv: 400, Sent: 4000,
283+
RecvCount: 2, SentCount: 2}, "Pear")
284+
285+
if statsAfter.ClientUser.BytesReceived.Counts == nil {
286+
t.Skip("Skipping ClientUser tests for statistics, since API is not present.")
287+
}
282288

283289
// First ask for a cursor on coordinator 1:
284290
req, err := conn.NewRequest("POST", "_db/statistics_test/_api/cursor")
@@ -338,25 +344,26 @@ func TestServerStatisticsForwarding(t *testing.T) {
338344
// the statistics calls):
339345
t.Logf("Checking user traffic on coordinator2...")
340346
checkTrafficAtMost(t, &statsBefore2, &statsAfter2, user,
341-
&limits{Received: 400, Sent: 4000,
342-
RecCount: 2, SentCount: 2})
347+
&limits{Recv: 400, Sent: 4000,
348+
RecvCount: 2, SentCount: 2}, "Apricot")
343349
// However, first coordinator should have counted the user traffic,
344350
// note: it was just a single request with nearly no upload but quite
345351
// some download:
346352
auth := os.Getenv("TEST_AUTHENTICATION")
347353
if auth != "super:testing" {
348354
t.Logf("Checking user traffic on coordinator1...")
355+
t.Logf("statsBefore1: %v\nstatsAfter1: %v", statsBefore1.ClientUser.BytesSent, statsAfter1.ClientUser.BytesSent)
349356
checkTrafficAtLeast(t, &statsBefore1, &statsAfter1, user,
350-
&limits{Received: 0, Sent: 40000,
351-
RecCount: 1, SentCount: 1})
357+
&limits{Recv: 0, Sent: 40000,
358+
RecvCount: 1, SentCount: 1}, "Jackfruit")
352359
} else {
353360
t.Logf("Checking traffic on coordinator1...")
354361
checkTrafficAtLeast(t, &statsBefore1, &statsAfter1, all,
355-
&limits{Received: 0, Sent: 40000,
356-
RecCount: 1, SentCount: 1})
362+
&limits{Recv: 0, Sent: 40000,
363+
RecvCount: 1, SentCount: 1}, "Durian")
357364
checkTrafficAtMost(t, &statsBefore1, &statsAfter1, user,
358-
&limits{Received: 0.1, Sent: 0.1,
359-
RecCount: 0, SentCount: 0})
365+
&limits{Recv: 0.1, Sent: 0.1,
366+
RecvCount: 0, SentCount: 0}, "Mango")
360367
}
361368
}
362369

0 commit comments

Comments
 (0)