carlos / platform Public

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

Plain git — no account needed to clone.

Download

Download this file

1//go:build linux
2
3package host
4
5import (
6 "testing"
7 "time"
8
9 "github.com/carlosframework/platform/internal/hostclaim"
10)
11
12// Carry 3, the install journal (Task 10 review M7): the local install
13// writes install.json under relocationJournals shared, so it waits while a
14// sweep holds the lock, and completes once the sweep lets go.
15func TestRelocationInstallJournalWaitsForTheSweep(t *testing.T) {
16 f := newInstallFixture(t, nil)
17 relocationJournals.Lock()
18 locked := true
19 defer func() {
20 if locked {
21 relocationJournals.Unlock()
22 }
23 }()
24 type result struct {
25 l hostclaim.LocalInstall
26 err error
27 }
28 done := make(chan result, 1)
29 go func() {
30 l, err := f.install()
31 done <- result{l, err}
32 }()
33 select {
34 case r := <-done:
35 t.Fatalf("installed beside the sweep: %+v %v", r.l, r.err)
36 case <-time.After(500 * time.Millisecond):
37 }
38 relocationJournals.Unlock()
39 locked = false
40 if r := <-done; r.err != nil {
41 t.Fatal(r.err)
42 }
43 path, _ := relocationInstallPath(f.r.DataDir, "rel-1")
44 if _, err := relocationJournalHost(path); err != nil {
45 t.Fatalf("the install journal: %v", err)
46 }
47}
48