package rpc import ( "testing" "time" agentv1 "git.ipao.vip/rogee/go-sip/gen/agent/v1" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) func TestSessionRegistryPersistsGenerationAcrossRestart(t *testing.T) { path := t.TempDir() + "/rpc-session.json" first := NewSessionRegistry(path) _, _, err := first.Activate(&agentv1.AgentBinding{AgentId: "agent-1", CellId: "cell-1", ExpectedBootId: "boot-1", DispatcherEpoch: "epoch-1", SessionGeneration: 3}, "activate-1", "digest-1", time.Unix(100, 0)) if err != nil { t.Fatal(err) } second := NewSessionRegistry(path) _, _, err = second.Activate(&agentv1.AgentBinding{AgentId: "agent-1", CellId: "cell-1", ExpectedBootId: "boot-2", DispatcherEpoch: "epoch-2", SessionGeneration: 2}, "activate-2", "digest-2", time.Unix(100, 0)) if status.Code(err) != codes.Aborted { t.Fatalf("error = %v, want persisted generation fence", err) } if _, _, err := second.Activate(&agentv1.AgentBinding{AgentId: "agent-1", CellId: "cell-1", ExpectedBootId: "boot-2", DispatcherEpoch: "epoch-2", SessionGeneration: 4}, "activate-3", "digest-3", time.Unix(100, 0)); err != nil { t.Fatal(err) } }