forked from mtusi2026/mtusi2026lab7
Prepare verified laboratory 7 implementation and evidence
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package lifecycle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMonitorStopsNormalWorkOnceOnFreshnessFailure(t *testing.T) {
|
||||
stops, reports := 0, 0
|
||||
r, e := New(Ports{Watch: func(context.Context) error { return errors.New("expired") }, Stop: func() { stops++ }, Report: func() { reports++ }})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
r.Run(context.Background())
|
||||
if stops != 1 || reports != 1 {
|
||||
t.Fatal("freshness failure did not stop normal work")
|
||||
}
|
||||
}
|
||||
func TestMonitorDoesNotReportNormalCancellation(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cancel()
|
||||
stops := 0
|
||||
r, e := New(Ports{Watch: func(context.Context) error { return context.Canceled }, Stop: func() { stops++ }, Report: func() { t.Fatal("normal stop reported failure") }})
|
||||
if e != nil {
|
||||
t.Fatal(e)
|
||||
}
|
||||
r.Run(ctx)
|
||||
if stops != 0 {
|
||||
t.Fatal("normal cancellation invoked failure stop")
|
||||
}
|
||||
}
|
||||
func TestMonitorRejectsMissingPorts(t *testing.T) {
|
||||
if _, e := New(Ports{}); e == nil {
|
||||
t.Fatal("process monitor accepted implicit production ports")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user