MCPcopy Index your code
hub / github.com/coder/coder / TestRunWithSMTP

Function TestRunWithSMTP

scaletest/notifications/run_test.go:159–325  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

157}
158
159func TestRunWithSMTP(t *testing.T) {
160 t.Parallel()
161
162 ctx := testutil.Context(t, testutil.WaitLong)
163 logger := testutil.Logger(t)
164 db, ps := dbtestutil.NewDB(t)
165
166 inboxHandler := dispatch.NewInboxHandler(logger.Named("inbox"), db, ps)
167
168 client := coderdtest.New(t, &coderdtest.Options{
169 Database: db,
170 Pubsub: ps,
171 })
172 firstUser := coderdtest.CreateFirstUser(t, client)
173
174 smtpAPIMux := http.NewServeMux()
175 smtpAPIMux.HandleFunc("/messages", func(w http.ResponseWriter, r *http.Request) {
176 summaries := []smtpmock.EmailSummary{
177 {
178 Subject: "TemplateUserAccountCreated",
179 Date: time.Now(),
180 NotificationTemplateID: notificationsLib.TemplateUserAccountCreated,
181 },
182 {
183 Subject: "TemplateUserAccountDeleted",
184 Date: time.Now(),
185 NotificationTemplateID: notificationsLib.TemplateUserAccountDeleted,
186 },
187 }
188
189 w.Header().Set("Content-Type", "application/json")
190 _ = json.NewEncoder(w).Encode(summaries)
191 })
192
193 smtpAPIServer := httptest.NewServer(smtpAPIMux)
194 defer smtpAPIServer.Close()
195
196 const numReceivingUsers = 2
197 const numRegularUsers = 2
198 dialBarrier := new(sync.WaitGroup)
199 receivingWatchBarrier := new(sync.WaitGroup)
200 dialBarrier.Add(numReceivingUsers + numRegularUsers)
201 receivingWatchBarrier.Add(numReceivingUsers)
202 metrics := notifications.NewMetrics(prometheus.NewRegistry())
203
204 eg, runCtx := errgroup.WithContext(ctx)
205
206 expectedNotificationsIDs := map[uuid.UUID]struct{}{
207 notificationsLib.TemplateUserAccountCreated: {},
208 notificationsLib.TemplateUserAccountDeleted: {},
209 }
210
211 mClock := quartz.NewMock(t)
212 smtpTrap := mClock.Trap().TickerFunc("smtp")
213 defer smtpTrap.Close()
214
215 httpClient := &http.Client{}
216

Callers

nothing calls this directly

Calls 15

CloseMethod · 0.95
ValidateMethod · 0.95
RunMethod · 0.95
CleanupMethod · 0.95
GetMetricsMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
NewDBFunction · 0.92
NewInboxHandlerFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
NewMetricsFunction · 0.92

Tested by

no test coverage detected