MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestDBStateChangeEvent

Function TestDBStateChangeEvent

db/event_manager_test.go:126–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

124}
125
126func TestDBStateChangeEvent(t *testing.T) {
127 ctx := base.TestCtx(t)
128 terminator := make(chan bool)
129 defer close(terminator)
130
131 em := NewEventManager(terminator)
132 em.Start(ctx, 0, -1)
133
134 // Setup test data
135 ids := make([]string, 20)
136 for i := 0; i < 20; i++ {
137 ids[i] = fmt.Sprintf("db%d", i)
138 }
139
140 resultChannel := make(chan interface{}, 20)
141 // Setup test handler
142 testHandler := &TestingHandler{HandledEvent: DBStateChange, t: t}
143 testHandler.SetChannel(resultChannel)
144 em.RegisterEventHandler(ctx, testHandler, DBStateChange)
145 // Raise online events
146 for i := 0; i < 10; i++ {
147 err := em.RaiseDBStateChangeEvent(ctx, ids[i], "online", "DB started from config", base.Ptr("0.0.0.0:0000"))
148 assert.NoError(t, err)
149 }
150 // Raise offline events
151 for i := 10; i < 20; i++ {
152 err := em.RaiseDBStateChangeEvent(ctx, ids[i], "offline", "Sync Gateway context closed", base.Ptr("0.0.0.0:0000"))
153 assert.NoError(t, err)
154 }
155
156 for i := 0; i < 25; i++ {
157 if len(resultChannel) == 20 {
158 break
159 }
160 }
161
162 assertChannelLengthWithTimeout(t, resultChannel, 20, 10*time.Second)
163
164}
165
166// Test sending many events with slow-running execution to validate they get dropped after hitting
167// the max concurrent goroutines

Callers

nothing calls this directly

Calls 8

StartMethod · 0.95
SetChannelMethod · 0.95
RegisterEventHandlerMethod · 0.95
TestCtxFunction · 0.92
PtrFunction · 0.92
NewEventManagerFunction · 0.85

Tested by

no test coverage detected