carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package host
2
3import (
4 "context"
5 "errors"
6 "github.com/carlosframework/platform/internal/hostguard"
7 "github.com/carlosframework/platform/internal/stopevidence"
8 "testing"
9)
10
11type fix1WritersScan struct {
12 stopKernelFunc
13 scan func()
14}
15
16func (k fix1WritersScan) VerifyWritersStopped(context.Context, hostguard.FenceTarget, StopInventory, StopPeer, []stopevidence.DescriptorHint) (WritersKernelEvidence, error) {
17 if k.scan != nil {
18 k.scan()
19 }
20 return WritersKernelEvidence{}, nil
21}
22
23func TestPlan11Fix1WritersMustRemainClosed(t *testing.T) {
24 for _, shape := range []string{"open", "unit-appears", "closed"} {
25 t.Run(shape, func(t *testing.T) {
26 f := newLaunchFixture(t, servingOp())
27 if shape != "open" {
28 if err := f.journal.CloseWriters(t.Context(), f.target); err != nil {
29 t.Fatal(err)
30 }
31 }
32 scans := 0
33 k := claimUnitStopKernel{Journal: f.journal, Units: f.units, Inner: fix1WritersScan{scan: func() {
34 scans++
35 if shape == "unit-appears" {
36 f.units.goneErr = errors.New("unit started during scan")
37 }
38 }}}
39 _, err := k.VerifyWritersStopped(t.Context(), f.target, StopInventory{}, f.peer, nil)
40 if shape == "closed" {
41 if err != nil || scans != 1 {
42 t.Fatalf("closed: %v, scans=%d", err, scans)
43 }
44 return
45 }
46 if err == nil {
47 t.Fatal("writers-stopped accepted an open writer boundary")
48 }
49 if shape == "open" && scans != 0 {
50 t.Fatal("scanned before writers closed")
51 }
52 })
53 }
54}
55