MCPcopy
hub / github.com/pocketbase/pocketbase / TestNotifyWatcher_SettingsUpdate

Function TestNotifyWatcher_SettingsUpdate

core/notify_watcher_test.go:16–88  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestNotifyWatcher_SettingsUpdate(t *testing.T) {
17 t.Parallel()
18
19 testEvents := store.New[core.App, int](nil)
20
21 tmpDir, err := os.MkdirTemp("", "pb_notify_test*")
22 if err != nil {
23 t.Fatal(err)
24 }
25 defer os.RemoveAll(tmpDir)
26
27 app1 := core.NewBaseApp(core.BaseAppConfig{
28 DataDir: tmpDir,
29 })
30 if err := app1.Bootstrap(); err != nil {
31 t.Fatal(err)
32 }
33
34 app2 := core.NewBaseApp(core.BaseAppConfig{
35 DataDir: tmpDir,
36 })
37 if err := app2.Bootstrap(); err != nil {
38 t.Fatal(err)
39 }
40
41 timeout := time.After(3 * time.Second)
42 done := make(chan struct{})
43
44 app1.OnSettingsReload().BindFunc(func(e *core.SettingsReloadEvent) error {
45 testEvents.SetFunc(app1, func(old int) int {
46 return old + 1
47 })
48 return e.Next()
49 })
50
51 app2.OnSettingsReload().BindFunc(func(e *core.SettingsReloadEvent) error {
52 testEvents.SetFunc(app2, func(old int) int {
53 defer func() {
54 done <- struct{}{}
55 }()
56
57 return old + 1
58 })
59 return e.Next()
60 })
61
62 // updating app1 settings should trigger a reload in app2
63 app1.Settings().SuperuserIPs = []string{"127.0.0.1"}
64 if err := app1.Save(app1.Settings()); err != nil {
65 t.Fatal(err)
66 }
67
68 // wait for the event
69 select {
70 case <-timeout:
71 t.Fatal("app2 reload event timeout")
72 case <-done:
73 // ready

Callers

nothing calls this directly

Calls 11

BootstrapMethod · 0.95
OnSettingsReloadMethod · 0.95
SettingsMethod · 0.95
SaveMethod · 0.95
NewBaseAppFunction · 0.92
AfterMethod · 0.80
SetFuncMethod · 0.80
NextMethod · 0.65
GetMethod · 0.65
RemoveAllMethod · 0.45
BindFuncMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…