Skip to content

Commit 1f42df8

Browse files
AnilAltinaygvisor-bot
authored andcommitted
Speedup Ruby test and hopefully reduce its flakiness
The Ruby test is flaky: 7 fails in 1000 runs. This CL creates the test image with the depencies ahead-of-time instead of just-in-time which brings down the test time from ~23s to below 2s. It also adds docker logs when the test fails. This should help with debugging hard to reproduce fails. PiperOrigin-RevId: 862091724
1 parent 1d8a7e9 commit 1f42df8

File tree

6 files changed

+34
-40
lines changed

6 files changed

+34
-40
lines changed

Makefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ integration-tests: docker-tests overlay-tests hostnet-tests swgso-tests
249249
integration-tests: do-tests kvm-tests containerd-tests-min
250250
.PHONY: integration-tests
251251

252+
integration-test-images: load-image-test load-basic
253+
.PHONY: integration-test-images
254+
252255
network-tests: ## Run all networking integration tests.
253256
network-tests: iptables-tests packetdrill-tests packetimpact-tests
254257
.PHONY: network-tests
@@ -367,7 +370,7 @@ portforward-tests: load-basic_redis load-basic_nginx $(RUNTIME_BIN)
367370
# Standard integration targets.
368371
INTEGRATION_TARGETS := //test/image:image_test //test/e2e:integration_test
369372

370-
docker-tests: load-basic $(RUNTIME_BIN)
373+
docker-tests: integration-test-images $(RUNTIME_BIN)
371374
@$(call install_runtime,$(RUNTIME),) # Clear flags.
372375
@$(call install_runtime,$(RUNTIME)-docker,--net-raw --allow-packet-socket-write) # Used by TestDocker*.
373376
@$(call install_runtime,$(RUNTIME)-fdlimit,--fdlimit=2000) # Used by TestRlimitNoFile.
@@ -378,30 +381,30 @@ docker-tests: load-basic $(RUNTIME_BIN)
378381
@$(call test_runtime_cached,$(RUNTIME),$(INTEGRATION_TARGETS) --test_env=TEST_SAVE_RESTORE_NETSTACK=true //test/e2e:integration_runtime_test //test/e2e:runtime_in_docker_test)
379382
.PHONY: docker-tests
380383

381-
plugin-network-tests: load-basic $(RUNTIME_BIN)
384+
plugin-network-tests: integration-test-images $(RUNTIME_BIN)
382385
@$(call install_runtime,$(RUNTIME)-dpdk,--network=plugin)
383386
@$(call test_runtime_cached,$(RUNTIME)-dpdk, --test_arg=-test.run=ConnectToSelf $(INTEGRATION_TARGETS))
384387

385388
plugin-network-tests: RUNSC_TARGET=--config plugin-tldk //runsc:runsc-plugin-stack
386389

387-
overlay-tests: load-basic $(RUNTIME_BIN)
390+
overlay-tests: integration-test-images $(RUNTIME_BIN)
388391
@$(call install_runtime,$(RUNTIME)-overlay,--overlay2=all:dir=/tmp)
389392
@$(call install_runtime,$(RUNTIME)-overlay-docker,--net-raw --allow-packet-socket-write --overlay2=all:dir=/tmp)
390393
@$(call test_runtime_cached,$(RUNTIME)-overlay,--test_env=TEST_OVERLAY=true $(INTEGRATION_TARGETS))
391394
.PHONY: overlay-tests
392395

393-
swgso-tests: load-basic $(RUNTIME_BIN)
396+
swgso-tests: integration-test-images $(RUNTIME_BIN)
394397
@$(call install_runtime,$(RUNTIME)-swgso,--software-gso=true --gso=false)
395398
@$(call install_runtime,$(RUNTIME)-swgso-docker,--net-raw --allow-packet-socket-write --software-gso=true --gso=false)
396399
@$(call test_runtime_cached,$(RUNTIME)-swgso,$(INTEGRATION_TARGETS))
397400
.PHONY: swgso-tests
398401

399-
hostnet-tests: load-basic $(RUNTIME_BIN)
402+
hostnet-tests: integration-test-images $(RUNTIME_BIN)
400403
@$(call install_runtime,$(RUNTIME)-hostnet,--network=host --net-raw)
401404
@$(call test_runtime_cached,$(RUNTIME)-hostnet,--test_env=TEST_CHECKPOINT=false --test_env=TEST_HOSTNET=true --test_env=TEST_NET_RAW=true $(INTEGRATION_TARGETS))
402405
.PHONY: hostnet-tests
403406

404-
kvm-tests: load-basic $(RUNTIME_BIN)
407+
kvm-tests: integration-test-images $(RUNTIME_BIN)
405408
@(lsmod | grep -E '^(kvm_intel|kvm_amd)') || sudo modprobe kvm
406409
@if ! test -w /dev/kvm; then sudo chmod a+rw /dev/kvm; fi
407410
@$(call test,//pkg/sentry/platform/kvm:kvm_test)
@@ -410,7 +413,7 @@ kvm-tests: load-basic $(RUNTIME_BIN)
410413
@$(call test_runtime_cached,$(RUNTIME)-kvm,$(INTEGRATION_TARGETS))
411414
.PHONY: kvm-tests
412415

413-
systrap-tests: load-basic $(RUNTIME_BIN)
416+
systrap-tests: integration-test-images $(RUNTIME_BIN)
414417
@$(call install_runtime,$(RUNTIME)-systrap,--platform=systrap)
415418
@$(call install_runtime,$(RUNTIME)-systrap-docker,--net-raw --allow-packet-socket-write --platform=systrap)
416419
@$(call test_runtime_cached,$(RUNTIME)-systrap,$(INTEGRATION_TARGETS))

images/image-test/ruby/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM ruby:3.3.5
2+
3+
RUN gem install sinatra rackup puma
4+
5+
COPY server.rb /server.rb
6+
CMD ["ruby", "/server.rb"]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@
1919

2020
get '/' do
2121
'Hello World'
22-
end
23-
22+
end

test/image/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ go_test(
1414
data = [
1515
"latin10k.txt",
1616
"mysql.sql",
17-
"ruby.rb",
18-
"ruby.sh",
1917
# runsc is needed to invalidate the bazel cache in case of any code changes.
2018
"//runsc",
2119
],

test/image/image_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ func TestTomcat(t *testing.T) {
273273
}
274274
}
275275

276+
func dockerLogs(ctx context.Context, d *dockerutil.Container) string {
277+
logs, err := d.Logs(ctx)
278+
if err != nil {
279+
return fmt.Sprintf("Failed to get docker logs: %v", err)
280+
}
281+
return logs
282+
}
283+
276284
func TestRuby(t *testing.T) {
277285
ctx := context.Background()
278286
d := dockerutil.MakeContainer(ctx, t)
@@ -281,10 +289,10 @@ func TestRuby(t *testing.T) {
281289
// Execute the ruby workload.
282290
port := 8080
283291
opts := dockerutil.RunOpts{
284-
Image: "basic/ruby",
292+
Image: "image-test/ruby",
285293
}
286-
d.CopyFiles(&opts, "/src", "test/image/ruby.rb", "test/image/ruby.sh")
287-
if err := d.Spawn(ctx, opts, "/src/ruby.sh"); err != nil {
294+
295+
if err := d.Spawn(ctx, opts); err != nil {
288296
t.Fatalf("docker run failed: %v", err)
289297
}
290298

@@ -294,26 +302,26 @@ func TestRuby(t *testing.T) {
294302
t.Fatalf("docker.FindIP failed: %v", err)
295303
}
296304

297-
// Wait until it's up and running, 'gem install' can take some time.
305+
// Wait until it's up and running.
298306
if err := testutil.WaitForHTTP(ip.String(), port, time.Minute); err != nil {
299-
t.Fatalf("WaitForHTTP() timeout: %v", err)
307+
t.Fatalf("WaitForHTTP() timeout: %v, docker logs: %v", err, dockerLogs(ctx, d))
300308
}
301309

302310
// Ensure that content is being served.
303311
url := fmt.Sprintf("http://%s:%d", ip.String(), port)
304312
resp, err := http.Get(url)
305313
if err != nil {
306-
t.Errorf("error reaching http server: %v", err)
314+
t.Errorf("error reaching http server: %v, docker logs: %v", err, dockerLogs(ctx, d))
307315
}
308316
if want := http.StatusOK; resp.StatusCode != want {
309-
t.Errorf("wrong response code, got: %d, want: %d", resp.StatusCode, want)
317+
t.Errorf("wrong response code, got: %d, want: %d, docker logs: %v", resp.StatusCode, want, dockerLogs(ctx, d))
310318
}
311319
body, err := io.ReadAll(resp.Body)
312320
if err != nil {
313-
t.Fatalf("error reading body: %v", err)
321+
t.Fatalf("error reading body: %v, docker logs: %v", err, dockerLogs(ctx, d))
314322
}
315323
if got, want := string(body), "Hello World"; !strings.Contains(got, want) {
316-
t.Errorf("invalid body content, got: %q, want: %q", got, want)
324+
t.Errorf("invalid body content, got: %q, want: %q, docker logs: %v", got, want, dockerLogs(ctx, d))
317325
}
318326
}
319327

test/image/ruby.sh

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)