45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package store
|
|
|
|
import (
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestCurrentStoreSnapshotPreservesAgentAndAllowsNewSIPRevision(t *testing.T) {
|
|
path := filepath.Join(t.TempDir(), "state.db")
|
|
s, err := OpenCurrent(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
snapshot := currentStoreSnapshot(t)
|
|
if err := s.SaveSnapshot(snapshot); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := s.Close(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s, err = OpenCurrent(path)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer s.Close()
|
|
loaded, err := s.ReadSnapshot(currentDispatcherID, 1001, "task-asr")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if loaded.SIP.Revision != 8 || loaded.Quota.MaxConcurrentCalls != 3 || loaded.Providers["asr-example"].Credential != "example-only-not-a-real-secret" || !strings.Contains(string(loaded.Task.Agent.Raw), `"interim":false`) {
|
|
t.Fatalf("binding was lost across restart: SIP=%d quota=%d agent=%s", loaded.SIP.Revision, loaded.Quota.MaxConcurrentCalls, loaded.Task.Agent.Raw)
|
|
}
|
|
snapshot.SIP.Revision = 9
|
|
snapshot.SIP.Trunks = []byte(strings.Replace(string(snapshot.SIP.Trunks), `"dial_prefix":""`, `"dial_prefix":"9"`, 1))
|
|
snapshot.Quota.QuotaRevision = 2
|
|
if err := s.SaveSnapshot(snapshot); err != nil {
|
|
t.Fatalf("same task revision with new global SIP/quota was rejected: %v", err)
|
|
}
|
|
loaded, err = s.ReadSnapshot(currentDispatcherID, 1001, "task-asr")
|
|
if err != nil || loaded.SIP.Revision != 9 || loaded.Quota.QuotaRevision != 2 {
|
|
t.Fatalf("global SIP/quota refresh not persisted: SIP=%d quota=%d err=%v", loaded.SIP.Revision, loaded.Quota.QuotaRevision, err)
|
|
}
|
|
}
|