From 81d1550df55318beff8e9f762952a33daaa7c0cf Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 27 Oct 2025 23:36:49 +0200 Subject: feat: Add randomSpread and RunInterval to checks This commit introduces two new optional parameters to the check configuration: - `randomSpread`: This parameter allows specifying a random sleep time up to N seconds before a check is executed. This is useful to avoid all checks running at the same time. - `RunInterval`: This parameter defines the minimum interval in seconds between two executions of a check. This is useful if gogios is run more frequently than a specific check should be. The `README.md` has been updated to document these new features. fix: Fix deadlock when skipping checks This commit also fixes a deadlock that occurred when a check was skipped due to the `RunInterval` setting. The `inputWg.Done()` was not being called, causing the main goroutine to wait forever. build: Replace Taskfile with Magefile The `Taskfile.yml` has been replaced with a `Magefile.go` to manage the build process. This provides more flexibility and is more idiomatic for Go projects. --- internal/state_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 internal/state_test.go (limited to 'internal/state_test.go') diff --git a/internal/state_test.go b/internal/state_test.go new file mode 100644 index 0000000..aacc023 --- /dev/null +++ b/internal/state_test.go @@ -0,0 +1,24 @@ +package internal + +import ( + "testing" + "time" +) + +func TestAge(t *testing.T) { + state := state{checks: make(map[string]checkState)} + + state.checks["Check Foo"] = checkState{Epoch: 0} + minAge := time.Duration(time.Now().Unix()) + + if reportedAge := state.age("Check Foo"); reportedAge < minAge { + t.Errorf("expected age >= %v, got %v", minAge, reportedAge) + } + + maxAge := time.Duration(time.Now().Unix()) + state.checks["Check Bar"] = checkState{Epoch: time.Now().Unix()} + + if reportedAge := state.age("Check Bar"); reportedAge >= minAge { + t.Errorf("expected age < %v, got %v", maxAge, reportedAge) + } +} -- cgit v1.2.3