internal/server/syncsvc/persistent_test.go
Ref: Size: 1.6 KiB History
package syncsvc
import (
"testing"
"github.com/a73x/eitri/internal/server/store"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// TestSnapshotStillCarriesPersistent is a compatibility pin, not a feature
// test. Persistence stopped being a column and stopped being a branch in this
// agent, but it has not stopped being on the wire, and this is the test that
// fails if someone finishes the job too early.
//
// A v0.0.5 agent — which exists, in production — reads VMSpec.persistent as
// a restart policy, and proto3 gives an absent bool the value false. False
// means ephemeral, and an ephemeral guest that goes lost is marked failed
// forever and never booted again. Every guest goes lost when its host reboots.
// So a server that stopped sending this field would, the first time a host
// running an older agent came back up, permanently strand every VM on it.
//
// The field comes out when no v0.0.5 agent can still be dialling in. Until
// then it is sent unconditionally, from nowhere: there is no stored value left
// to read, which is the point.
func TestSnapshotStillCarriesPersistent(t *testing.T) {
f := setup(t)
require.NoError(t, f.st.CreateVM(store.VM{
ID: "vm1", HostID: f.host.ID, Name: "web-1", ImageURL: "u", ImageSHA256: "s",
VCPUs: 1, MemMB: 512, DiskGB: 5, PowerState: "running",
}))
snap, err := f.svc.buildSnapshot(f.host.ID)
require.NoError(t, err)
require.Len(t, snap.GetVms(), 1)
assert.True(t, snap.GetVms()[0].GetPersistent(),
"a fielded v0.0.5 agent reads an absent persistent as ephemeral and strands the guest")
}