MCPcopy Index your code
hub / github.com/pocketbase/pocketbase / TestNotifyWatcher_CollectionsUpdate

Function TestNotifyWatcher_CollectionsUpdate

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

Source from the content-addressed store, hash-verified

88}
89
90func TestNotifyWatcher_CollectionsUpdate(t *testing.T) {
91 t.Parallel()
92
93 tmpDir, err := os.MkdirTemp("", "pb_notify_test*")
94 if err != nil {
95 t.Fatal(err)
96 }
97 defer os.RemoveAll(tmpDir)
98
99 app1 := core.NewBaseApp(core.BaseAppConfig{
100 DataDir: tmpDir,
101 })
102 if err := app1.Bootstrap(); err != nil {
103 t.Fatal(err)
104 }
105
106 app2 := core.NewBaseApp(core.BaseAppConfig{
107 DataDir: tmpDir,
108 })
109 if err := app2.Bootstrap(); err != nil {
110 t.Fatal(err)
111 }
112
113 testQueries := store.New[string, []string](nil)
114 app2.ConcurrentDB().(*dbx.DB).QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {
115 testQueries.SetFunc("concurrent", func(old []string) []string {
116 return append(old, sql)
117 })
118 }
119 app2.ConcurrentDB().(*dbx.DB).ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) {
120 testQueries.SetFunc("concurrent", func(old []string) []string {
121 return append(old, sql)
122 })
123 }
124 app2.NonconcurrentDB().(*dbx.DB).QueryLogFunc = func(ctx context.Context, t time.Duration, sql string, rows *sql.Rows, err error) {
125 testQueries.SetFunc("nonconcurrent", func(old []string) []string {
126 return append(old, sql)
127 })
128 }
129 app2.NonconcurrentDB().(*dbx.DB).ExecLogFunc = func(ctx context.Context, t time.Duration, sql string, result sql.Result, err error) {
130 testQueries.SetFunc("nonconcurrent", func(old []string) []string {
131 return append(old, sql)
132 })
133 }
134
135 ctx, cancelCtx := context.WithTimeout(context.Background(), 1*time.Second)
136 defer cancelCtx()
137
138 sem := semaphore.NewWeighted(1)
139 sem.Acquire(ctx, 1)
140
141 // currently there is no hook for the collections cache reload so we pool instead
142 done := make(chan bool, 1)
143 ticker := time.NewTicker(100 * time.Millisecond)
144 go func() {
145 for {
146 select {
147 case <-ticker.C:

Callers

nothing calls this directly

Calls 12

BootstrapMethod · 0.95
ConcurrentDBMethod · 0.95
NonconcurrentDBMethod · 0.95
SaveMethod · 0.95
DeleteMethod · 0.95
NewBaseAppFunction · 0.92
NewBaseCollectionFunction · 0.92
SetFuncMethod · 0.80
StopMethod · 0.80
GetMethod · 0.65
RemoveAllMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…