Skip to content

Commit 6965d9b

Browse files
authored
Fix playwright test flakiness (#1495)
* Fix playwright test flakiness During the saved search playwright tests, we kill and reopen the ports needed for the database (as well as all other ports). We do this because beforehand, we did not port forward the ports for the database and only the ports needed to connect to the app (the backend already had access to the database internally) But instead of doing that, we now port forward the database ports. Then we have a new helper makefile target to check if the port is live. We use `nc` instead of curl because it did not work with grpc. The devcontainer Dockerfile has been updated to install that dependency (devs will need to rebuild their devcontainer) Hopefully, this will reduce the times when the port fails to forward again on subsequent tries since we never have to forward it again. One thing to note: Now developers will need to run make port-forward-manual first before dev_fake_data and other commands after running start-local * revert limit for datastore * further increase spanner limit * dev_fake_data already calls check-local-ports
1 parent ce2c8c2 commit 6965d9b

10 files changed

Lines changed: 52 additions & 36 deletions

File tree

.dev/auth/manifests/pod.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ spec:
2828
name: auth-port
2929
- containerPort: 9100
3030
name: auth-ui-port
31+
readinessProbe:
32+
tcpSocket:
33+
port: 9099
34+
initialDelaySeconds: 15
3135
startupProbe:
3236
httpGet:
3337
port: auth-ui-port

.dev/datastore/manifests/pod.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@ spec:
3333
requests:
3434
cpu: 100m
3535
memory: 128Mi
36+
readinessProbe:
37+
tcpSocket:
38+
port: 8086
39+
initialDelaySeconds: 10

.dev/spanner/manifests/pod.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@ spec:
2828
name: grpc-port
2929
- containerPort: 9020
3030
name: rest-port
31+
readinessProbe:
32+
tcpSocket:
33+
port: 9010
34+
initialDelaySeconds: 10
3135
resources:
3236
limits:
3337
cpu: '2'
34-
memory: '3.5Gi'
38+
memory: '5.5Gi'
3539
requests:
3640
cpu: '300m'
3741
memory: '256Mi'

.dev/valkey/manifests/pod.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ spec:
2626
ports:
2727
- containerPort: 6379
2828
name: valkey-port
29+
readinessProbe:
30+
tcpSocket:
31+
port: 6379
2932
resources:
3033
limits:
3134
cpu: 250m

.devcontainer/Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ RUN echo "alias grun='java org.antlr.v4.gui.TestRig'" >> ~/.bashrc
3535

3636
ENV CLASSPATH=.:/usr/local/lib/antlr-${ANTLR4_VERSION}-complete.jar
3737

38+
# Install netcat (nc)
39+
RUN apt-get update && apt-get install -y netcat-traditional
40+
3841
# Switch to the default user and append to PATH
3942
USER vscode
4043

Makefile

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,10 @@ deploy-local: configure-skaffold
6262
delete-local:
6363
skaffold delete $(SKAFFOLD_FLAGS) || true
6464

65-
# TODO: In the future, we should install netcat
6665
define wait_for_port
6766
@echo "Waiting for $(2) on port $(1) to respond..."
6867
@for i in $$(seq 1 5); do \
69-
if curl -s -f -o /dev/null -m 2 http://localhost:$(1)$(3); then \
68+
if nc -zvw 2 localhost $(1); then \
7069
echo "$(2) on port $(1) is responding."; \
7170
exit 0; \
7271
fi; \
@@ -80,30 +79,42 @@ define wait_for_port
8079
done
8180
endef
8281

82+
83+
check-local-ports:
84+
$(call wait_for_port,5555,frontend)
85+
$(call wait_for_port,8080,backend)
86+
$(call wait_for_port,9099,auth-main)
87+
$(call wait_for_port,9100,auth-aux)
88+
$(call wait_for_port,9010,spanner)
89+
$(call wait_for_port,8086,datastore)
90+
8391
port-forward-manual: port-forward-terminate
8492
kubectl wait --for=condition=ready pod/frontend
8593
kubectl wait --for=condition=ready pod/backend
8694
kubectl wait --for=condition=ready pod/auth
95+
kubectl wait --for=condition=ready pod/datastore
96+
kubectl wait --for=condition=ready pod/spanner
8797
kubectl port-forward --address 127.0.0.1 pod/frontend 5555:5555 2>&1 >/dev/null &
8898
kubectl port-forward --address 127.0.0.1 pod/backend 8080:8080 2>&1 >/dev/null &
8999
kubectl port-forward --address 127.0.0.1 pod/auth 9099:9099 2>&1 >/dev/null &
90100
kubectl port-forward --address 127.0.0.1 pod/auth 9100:9100 2>&1 >/dev/null &
91-
$(call wait_for_port,5555,frontend,/)
92-
$(call wait_for_port,8080,backend,/v1/features?page_size=1)
93-
$(call wait_for_port,9099,auth-main,/)
94-
$(call wait_for_port,9100,auth-aux,/)
101+
kubectl port-forward --address 127.0.0.1 pod/spanner 9010:9010 2>&1 >/dev/null &
102+
kubectl port-forward --address 127.0.0.1 pod/datastore 8086:8086 2>&1 >/dev/null &
103+
make check-local-ports
95104

96105
port-forward-terminate:
97106
fuser -k 5555/tcp || true
98107
fuser -k 8080/tcp || true
99108
fuser -k 9099/tcp || true
100109
fuser -k 9100/tcp || true
110+
fuser -k 9010/tcp || true
111+
fuser -k 8086/tcp || true
101112

102113
# Prerequisite target to start minikube if necessary
103114
minikube-running:
104115
# Check if minikube is running using a shell command
105116
@if ! minikube status -p "$${MINIKUBE_PROFILE}" | grep -q "Running"; then \
106-
minikube start -p "$${MINIKUBE_PROFILE}" --cni calico --disk-size=10gb --cpus=2 --memory=4096m; \
117+
minikube start -p "$${MINIKUBE_PROFILE}" --cni calico --disk-size=10gb --cpus=2 --memory=6g; \
107118
fi
108119
minikube-clean-restart: minikube-delete minikube-running
109120
minikube-delete:
@@ -313,7 +324,7 @@ license-fix:
313324
# fresh-env-for-playwright prerequisite. If unset, the fresh environment will be created.
314325
SKIP_FRESH_ENV ?=
315326

316-
fresh-env-for-playwright: $(if $(SKIP_FRESH_ENV),,playwright-install delete-local build deploy-local dev_fake_users dev_fake_data port-forward-manual)
327+
fresh-env-for-playwright: $(if $(SKIP_FRESH_ENV),,playwright-install delete-local build deploy-local port-forward-manual dev_fake_users dev_fake_data)
317328

318329
playwright-install:
319330
npx playwright install --with-deps
@@ -413,26 +424,14 @@ dev_fake_users: build
413424
fuser -k 9099/tcp || true
414425
kubectl port-forward --address 127.0.0.1 pod/auth 9099:9099 2>&1 >/dev/null &
415426
go run util/cmd/load_test_users/main.go -project=local
416-
dev_fake_data: build is_local_migration_ready
417-
fuser -k 9010/tcp || true
418-
kubectl wait --for=condition=ready pod/spanner
419-
kubectl port-forward --address 127.0.0.1 pod/spanner 9010:9010 2>&1 >/dev/null &
420-
fuser -k 8086/tcp || true
421-
kubectl wait --for=condition=ready pod/datastore
422-
kubectl port-forward --address 127.0.0.1 pod/datastore 8086:8086 2>&1 >/dev/null &
423-
fuser -k 9099/tcp || true
424-
kubectl wait --for=condition=ready pod/auth
425-
kubectl port-forward --address 127.0.0.1 pod/auth 9099:9099 2>&1 >/dev/null &
427+
dev_fake_data: build is_local_migration_ready check-local-ports
426428
SPANNER_EMULATOR_HOST=localhost:9010 DATASTORE_EMULATOR_HOST=localhost:8086 FIREBASE_AUTH_EMULATOR_HOST=localhost:9099 \
427429
go run ./util/cmd/load_fake_data/main.go \
428430
-spanner_project=local \
429431
-spanner_instance=local \
430432
-spanner_database=local \
431433
-datastore_project=local \
432434
$(LOAD_FAKE_DATA_FLAGS)
433-
fuser -k 9099/tcp || true
434-
fuser -k 9010/tcp || true
435-
fuser -k 8086/tcp || true
436435
is_local_migration_ready:
437436
kubectl wait --for=condition=ready --timeout=300s pod/spanner
438437
@MAX_RETRIES=5; SLEEP_INTERVAL=5 ; \

backend/manifests/pod.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ spec:
2626
ports:
2727
- containerPort: 8080
2828
name: http-backend
29+
readinessProbe:
30+
tcpSocket:
31+
port: 8080
2932
env:
3033
- name: SPANNER_DATABASE
3134
value: 'local'

docs/testing.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ Developers may still need to inspect and manually fix the error.
6161
### Note about running Playwright Makefile Targets
6262

6363
If you have a running local development environment
64-
(established via `make start-local`) with the necessary fake users (`make dev_fake_users`),
65-
fake data (`make dev_fake_data`), and port forwarding
66-
(`make port-forward-manual`), you can expedite Playwright testing by skipping
67-
the environment setup.
64+
(established via `make start-local`) with the necessary port forwarding
65+
(`make port-forward-manual`), fake users (`make dev_fake_users`) and
66+
fake data (`make dev_fake_data`), you can expedite Playwright testing by
67+
skipping the environment setup.
6868

6969
To do this, prefix your `make` command with `SKIP_FRESH_ENV=1`. This is
7070
particularly useful for rapid iteration, as `make start-local` leverages

e2e/tests/utils.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,12 @@ export async function resetUserData() {
122122
const projectRootDir = path.resolve(__dirname, '../..');
123123

124124
try {
125-
const cmd1 = `make dev_fake_data -o build -o is_local_migration_ready LOAD_FAKE_DATA_FLAGS='-scope=user -reset'`;
125+
const cmd = `make dev_fake_data -o build -o is_local_migration_ready LOAD_FAKE_DATA_FLAGS='-scope=user -reset'`;
126126

127-
console.log(`Executing command: ${cmd1} in ${projectRootDir}`);
128-
execSync(cmd1, {cwd: projectRootDir, stdio: 'inherit'});
127+
console.log(`Executing command: ${cmd} in ${projectRootDir}`);
128+
execSync(cmd, {cwd: projectRootDir, stdio: 'inherit'});
129129

130130
console.log('Reset command finished successfully.');
131-
132-
const cmd2 = 'make port-forward-manual';
133-
console.log(`Executing command: ${cmd2} in ${projectRootDir}`);
134-
execSync(cmd2, {
135-
cwd: projectRootDir,
136-
stdio: 'inherit',
137-
});
138131
} catch (error) {
139132
console.error('Error reset command (make dev_fake_data):', error);
140133
throw new Error('Reset command finished, halting tests.');

frontend/manifests/pod.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ spec:
2929
ports:
3030
- containerPort: 5555
3131
name: http-frontend
32+
readinessProbe:
33+
tcpSocket:
34+
port: 5555
3235
env:
3336
- name: API_URL
3437
value: http://localhost:8080

0 commit comments

Comments
 (0)