Repository navigation
Expand file tree
/
Copy pathexport_test.go
More file actions
61 lines (56 loc) · 1.86 KB
/
Copy pathexport_test.go
File metadata and controls
61 lines (56 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright 2026 Swytch Labs BV
*
* This file is part of Swytch.
*
* Swytch is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* Swytch is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Swytch. If not, see <https://www.gnu.org/licenses/>.
*/
package caddy
import (
"testing"
"github.com/swytchdb/engine/beacon"
"github.com/swytchdb/engine/effects"
)
// resetRuntimeForTest tears the singleton down so a test can reinitialise
// it with different config. A Stop failure is reported via t.Errorf so
// teardown problems surface as test failures rather than being lost —
// we don't t.Fatalf because cleanup paths must continue regardless.
func resetRuntimeForTest(t testing.TB) {
t.Helper()
runtimeMu.Lock()
defer runtimeMu.Unlock()
if currentRuntime == nil {
return
}
rt := currentRuntime.rt
currentRuntime = nil
if err := rt.Stop(); err != nil {
t.Errorf("resetRuntimeForTest: runtime.Stop: %v", err)
}
}
// installTestRuntime injects an already-constructed engine as the
// process-wide runtime. Tests use this to drive the storage layer
// without standing up a full beacon (no cluster port bind, no DNS).
func installTestRuntime(eng *effects.Engine, keyPrefix string) {
runtimeMu.Lock()
defer runtimeMu.Unlock()
sr := &sharedRuntime{
rt: &beacon.Runtime{Engine: eng},
waiters: newWaiters(),
keyPrefix: keyPrefix,
refs: 1,
}
wireLockWakeups(eng, sr)
currentRuntime = sr
}