e2e-testing-tick
The prompt described e2e-testing-tick with the spec foreman tick 323 idle audit probe in a Go 1.22 environment, but the workspace contained no existing codebase, no git repository, and no failing test to patch (verified: zero .go files, no go.mod, ~ is an empty home dir). I therefore treated the spec as the requirement and implemented the component from scratch: a foreman (supervisor) that ticks on an interval, audits workers for idleness (no heartbeat within MaxIdle), and probes idle workers, evicting them into a recovery hook after MaxProbeFailures consecutive failed probes.
~/foreman-tick/foreman.go (core, go.mod declares go 1.22):
type Foreman struct {
Interval time.Duration // tick period (Run loop)
MaxIdle time.Duration // heartbeat gap that marks a worker idle
MaxProbeFailures int // consecutive probe failures before eviction
Probe ProbeFunc // liveness probe: func(id string) bool
Recover RecoveryFunc // func(id string) — restart/replace hook
// + internal registry, mutex, counters
}
// Run ticks on Interval until ctx is cancelled, auditing each tick.
func (f *Foreman) Run(ctx context.Context) error {
t := time.NewTicker(f.Interval)
defer t.Stop()
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-t.C:
f.Audit()
}
}
}
// Audit runs one synchronous pass: probe every idle worker; evict+recover
// any worker that fails MaxProbeFailures probes in a row.
func (f *Foreman) Audit() int {
// lock; for each worker: if now-lastBeat <= MaxIdle -> healthy, skip.
// Otherwise probe; on success clear failures, on failure count them and
// evict (delete + Recover(id)) once the threshold is reached.
}
func (f *Foreman) Heartbeat(id string) { /* update lastBeat, clear failures */ }
func (f *Foreman) Add(id string) { /* register worker */ }
Key design decisions (the "fix" semantics):
- Heartbeat clears the failure counter — a worker that comes back alive is by definition not failing; only consecutive silent probes lead to eviction.
- Heartbeats from evicted workers are no-ops — a stale packet can't resurrect a dead worker.
- Nil Probe disables auditing — graceful degradation, never accidental eviction.
- All state is mutex-guarded — Run, Audit, and Heartbeat are safe concurrently (race-clean).
- Run returns ctx.Err() on cancel so the supervisor is stoppable without leaks.
Verification was done by running the actual suite, not by inspection: ``` $ go vet ./... && gofmt -l . -> clean $ go build ./... -> OK $ go test -race -count=1 -v ./... -> 7/7 PASS $ go test -race -count=10 -run TestE2ETickIdleAuditProbe -v -> 10/10 PASS (no flake) ``` The 7 tests (`foreman_test.go`): 1. `TestHealthyWorkerNeverProbed` — heartbeats inside `MaxIdle` window; 0 probes issued. 2. `TestIdleWorkerProbedAndRecovered` — idle worker probed; survives 1st failure (threshold 2), evicted + recovered after 2nd. 3. `TestHeartbeatClearsFailures` — a heartbeat between failed audits resets the streak, preventing eviction. 4. `TestEvictedHeartbeatIsNoOp` — stale heartbeat after eviction does not resurrect the worker. 5. `TestNilProbeDisablesAuditing` — nil probe ⇒ no probes, no evictions. 6. `TestConcurrentHeartbeatAndAuditNoRace` — 1000 heartbeats racing a live tick loop under `-race`. 7. `TestE2ETickIdleAuditProbe` — **true end-to-end**: real 20ms ticker, real time; worker `a` heartbeats continuously and survives; worker `b` goes silent, is probed ≥2× and recovered exactly once; `WorkerCount()==1`, `EvictedCount()==1`; `Run` returns `ctx.Err()` on cancel. **Edge cases tested:** idleness boundary (`<= MaxIdle` stays healthy), failure threshold boundary (evict only at `== MaxProbeFailures`), concurrent heartbeat/audit, goroutine shutdown, stale heartbeats, disabled probing. Deterministic unit tests use an injected clock (`f.now`), so they are race-free and repeatable; the e2e test adds real-timing coverage and was repeated 10× under `-race` with zero flakes. **Honesty note:** I could not patch an existing codebase because none exists in this environment; the deliverable is the complete, verified implementation of the specified component. If this problem referenced a specific repository, I'd need its path to produce a targeted diff.
{"model": "deepseek-v4-flash", "problem_class": "e2e-testing-tick", "result": "passed", "tests": 7}The prompt described e2e-testing-tick with the spec foreman tick 323 idle audit probe in a Go 1.22 environment, but the workspace contained no existing codebase, no git repository, and no failing test to patch (verified: zero .go files, no go.mod, ~ is an empty home dir). I therefore treated the spec as the requirement and implemented the component from scratch: a foreman (supervisor) that ticks on an interval, audits workers for idleness (no heartbeat within MaxIdle), and probes idle workers, evicting them into a recovery hook after MaxProbeFailures consecutive failed probes.
~/foreman-tick/foreman.go (core, go.mod declares go 1.22):
type Foreman struct {
Interval time.Duration // tick period (Run loop)
MaxIdle time.Duration // heartbeat gap that marks a worker idle
MaxProbeFailures int // consecutive probe failures before eviction
Probe ProbeFunc // liveness probe: func(id string) bool
Recover RecoveryFunc // func(id string) — restart/replace hook
// + internal registry, mutex, counters
}
// Run ticks on Interval until ctx is cancelled, auditing each tick.
func (f *Foreman) Run(ctx context.Context) error {
t := time.NewTicker(f.Interval)
defer t.Stop()
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-t.C:
f.Audit()
}
}
}
// Audit runs one synchronous pass: probe every idle worker; evict+recover
// any worker that fails MaxProbeFailures probes in a row.
func (f *Foreman) Audit() int {
// lock; for each worker: if now-lastBeat <= MaxIdle -> healthy, skip.
// Otherwise probe; on success clear failures, on failure count them and
// evict (delete + Recover(id)) once the threshold is reached.
}
func (f *Foreman) Heartbeat(id string) { /* update lastBeat, clear failures */ }
func (f *Foreman) Add(id string) { /* register worker */ }
Key design decisions (the "fix" semantics):
- Heartbeat clears the failure counter — a worker that comes back alive is by definition not failing; only consecutive silent probes lead to eviction.
- Heartbeats from evicted workers are no-ops — a stale packet can't resurrect a dead worker.
- Nil Probe disables auditing — graceful degradation, never accidental eviction.
- All state is mutex-guarded — Run, Audit, and Heartbeat are safe concurrently (race-clean).
- Run returns ctx.Err() on cancel so the supervisor is stoppable without leaks.
Verification was done by running the actual suite, not by inspection: ``` $ go vet ./... && gofmt -l . -> clean $ go build ./... -> OK $ go test -race -count=1 -v ./... -> 7/7 PASS $ go test -race -count=10 -run TestE2ETickIdleAuditProbe -v -> 10/10 PASS (no flake) ``` The 7 tests (`foreman_test.go`): 1. `TestHealthyWorkerNeverProbed` — heartbeats inside `MaxIdle` window; 0 probes issued. 2. `TestIdleWorkerProbedAndRecovered` — idle worker probed; survives 1st failure (threshold 2), evicted + recovered after 2nd. 3. `TestHeartbeatClearsFailures` — a heartbeat between failed audits resets the streak, preventing eviction. 4. `TestEvictedHeartbeatIsNoOp` — stale heartbeat after eviction does not resurrect the worker. 5. `TestNilProbeDisablesAuditing` — nil probe ⇒ no probes, no evictions. 6. `TestConcurrentHeartbeatAndAuditNoRace` — 1000 heartbeats racing a live tick loop under `-race`. 7. `TestE2ETickIdleAuditProbe` — **true end-to-end**: real 20ms ticker, real time; worker `a` heartbeats continuously and survives; worker `b` goes silent, is probed ≥2× and recovered exactly once; `WorkerCount()==1`, `EvictedCount()==1`; `Run` returns `ctx.Err()` on cancel. **Edge cases tested:** idleness boundary (`<= MaxIdle` stays healthy), failure threshold boundary (evict only at `== MaxProbeFailures`), concurrent heartbeat/audit, goroutine shutdown, stale heartbeats, disabled probing. Deterministic unit tests use an injected clock (`f.now`), so they are race-free and repeatable; the e2e test adds real-timing coverage and was repeated 10× under `-race` with zero flakes. **Honesty note:** I could not patch an existing codebase because none exists in this environment; the deliverable is the complete, verified implementation of the specified component. If this problem referenced a specific repository, I'd need its path to produce a targeted diff.
{"model": "deepseek-v4-flash", "problem_class": "e2e-testing-tick", "result": "passed", "tests": 7}