mirror of
https://github.com/status-im/go-watchdog.git
synced 2025-02-04 21:53:24 +00:00
8676adea5c
This commit introduces the cgroup-driven watchdog. It can be initialized by calling watchdog.CgroupDriven(). This watchdog infers the limit from the process' cgroup, which is either derived from /proc/self/cgroup, or from the root cgroup if the PID == 1 (running in a container). Tests have been added/refactored to accommodate running locally and in a Docker container. Certain test cases now must be isolated from one another, to prevent side-effects from dirty go runtimes. A Makefile has been introduced to run all tests.
31 lines
1.1 KiB
Makefile
31 lines
1.1 KiB
Makefile
SHELL = /bin/bash
|
|
|
|
.PHONY: test
|
|
|
|
# these tests run in isolation by calling go test -run=... or the equivalent.
|
|
ISOLATED_TESTS = TestControl_Isolated \
|
|
TestSystemDriven_Isolated \
|
|
TestHeapDriven_Isolated \
|
|
TestCgroupsDriven_Create_Isolated \
|
|
TestCgroupsDriven_Docker_Isolated
|
|
|
|
test: test-binary test-docker
|
|
|
|
test-binary:
|
|
go test -v ./... # run all the non-isolated tests.
|
|
# foreach does not actually execute each iteration; it expands the text, and it's executed all at once
|
|
# that's why we use && true, to shorcircuit if a test fails.
|
|
$(foreach name,$(ISOLATED_TESTS),TEST_ISOLATED=1 go test -v -test.run=$(name) ./... && ) true
|
|
|
|
test-docker: docker
|
|
docker run --memory=32MiB --memory-swap=32MiB -e TEST_DOCKER_MEMLIMIT=33554432 raulk/watchdog:latest
|
|
$(foreach name,$(ISOLATED_TESTS),docker run \
|
|
--memory=32MiB --memory-swap=32MiB \
|
|
-e TEST_ISOLATED=1 \
|
|
-e TEST_DOCKER_MEMLIMIT=33554432 \
|
|
raulk/watchdog:latest /root/watchdog.test -test.v -test.run=$(name) ./... && ) true
|
|
|
|
docker:
|
|
docker build -f ./Dockerfile.test -t raulk/watchdog:latest .
|
|
|