Prevent spurious /dev/shm/PostgreSQL.* files in tests
By default the postgres server uses `shm_open(3)` to create shared
memory to talk between workers. This means files directly inside of
`/dev/shm`. Since that directory is one of the few (maybe only?)
world-writeable and non-sandboxed directories, that means the server
can leave behind these useless files.
I investigated switching postgres to use the `sysv` mechanism for IPC,
but that doesn't really help us here. That just creates shared memory
segments that are even harder to track and clean up after a run.
For example:
https://www.ibm.com/docs/en/aix/7.2?topic=s-shmget-subroutine
> Once created, a shared memory segment is deleted only when the
> system reboots or by issuing the ipcrm command or using the following
> shmctl subroutine:
The final approach here is to make the test framework properly shut
down the various servers. It currently just expects the bazel sandbox
to kill the servers. I couldn't find a way to get node to
synchronously shut down the servers and wait for them to finish
shutting down. All node APIs I could find for this are asynchronous.
Those APIs cannot be used in node's `exit` hook, unfortunately. To
that end I wrote a node binding for the `waitpid(2)` syscall. This
forces node to wait for the servers to shut down before exiting the
test. This means we don't leave spurious files behind at the end of
the test in normal circumstances.
After this patch, I don't see any spurious files left behind anymore.
$ bazel test --runs_per_test=40 //scouting:scouting_test_chromium-local
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: Id798a1339cf4076c82bf31b94cc972476b57850b
diff --git a/tools/build_rules/js.bzl b/tools/build_rules/js.bzl
index f5a7543..5510266 100644
--- a/tools/build_rules/js.bzl
+++ b/tools/build_rules/js.bzl
@@ -63,7 +63,7 @@
},
)
-def protractor_ts_test(name, srcs, deps = None, **kwargs):
+def protractor_ts_test(name, srcs, deps = None, data = None, **kwargs):
"""Wraps upstream protractor_web_test_suite() to reduce boilerplate.
This is largely based on the upstream protractor example:
@@ -89,9 +89,14 @@
declaration_map = True,
)
+ data = (data or []) + [
+ "//tools/build_rules/js/waitpid_module",
+ ]
+
protractor_web_test_suite(
name = name,
srcs = [paths.replace_extension(src, ".js") for src in srcs],
deps = [":%s__lib" % name],
+ data = data,
**kwargs
)