Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1f7148e

Browse files
committed
extract goroutine to separate function
1 parent4c615f2 commit1f7148e

File tree

1 file changed

+105
-83
lines changed

1 file changed

+105
-83
lines changed

‎cli/exp_scaletest.go‎

Lines changed: 105 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,89 +2060,16 @@ func (r *RootCmd) scaletestNotifications() *serpent.Command {
20602060
configs=append(configs,config)
20612061
}
20622062

2063-
gofunc() {
2064-
logger.Info(ctx,"waiting for owner users to connect")
2065-
2066-
// Wait for owner users to connect
2067-
ownerWaitCtx,cancel:=context.WithTimeout(ctx,dialTimeout+30*time.Second)
2068-
defercancel()
2069-
2070-
ownerDone:=make(chanstruct{})
2071-
gofunc() {
2072-
ownerDialBarrier.Wait()
2073-
close(ownerDone)
2074-
}()
2075-
2076-
select {
2077-
case<-ownerDone:
2078-
logger.Info(ctx,"all owner users connected")
2079-
case<-ownerWaitCtx.Done():
2080-
ifownerWaitCtx.Err()==context.DeadlineExceeded {
2081-
logger.Error(ctx,"timeout waiting for owner users to connect")
2082-
}else {
2083-
logger.Info(ctx,"context canceled while waiting for owner users")
2084-
}
2085-
return
2086-
}
2087-
2088-
// Wait for regular users to connect
2089-
logger.Info(ctx,"waiting for regular users to connect")
2090-
regularWaitCtx,cancel:=context.WithTimeout(ctx,dialTimeout+30*time.Second)
2091-
defercancel()
2092-
2093-
regularDone:=make(chanstruct{})
2094-
gofunc() {
2095-
regularDialBarrier.Wait()
2096-
close(regularDone)
2097-
}()
2098-
2099-
select {
2100-
case<-regularDone:
2101-
logger.Info(ctx,"all regular users connected")
2102-
case<-regularWaitCtx.Done():
2103-
ifregularWaitCtx.Err()==context.DeadlineExceeded {
2104-
logger.Error(ctx,"timeout waiting for regular users to connect")
2105-
}else {
2106-
logger.Info(ctx,"context canceled while waiting for regular users")
2107-
}
2108-
return
2109-
}
2110-
2111-
logger.Info(ctx,"all users connected, triggering notifications")
2112-
2113-
const (
2114-
triggerUsername="scaletest-trigger-user"
2115-
triggerEmail="scaletest-trigger@example.com"
2116-
)
2117-
2118-
logger.Info(ctx,"creating test user to test notifications",
2119-
slog.F("username",triggerUsername),
2120-
slog.F("email",triggerEmail),
2121-
slog.F("org_id",me.OrganizationIDs[0]))
2122-
2123-
createTime:=time.Now()
2124-
testUser,err:=client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
2125-
OrganizationIDs: []uuid.UUID{me.OrganizationIDs[0]},
2126-
Username:triggerUsername,
2127-
Email:triggerEmail,
2128-
Password:"test-password-123",
2129-
})
2130-
iferr!=nil {
2131-
logger.Error(ctx,"create test user",slog.Error(err))
2132-
return
2133-
}
2134-
expectedNotifications[notificationsLib.TemplateUserAccountCreated]<-createTime
2135-
2136-
deleteTime:=time.Now()
2137-
err=client.DeleteUser(ctx,testUser.ID)
2138-
iferr!=nil {
2139-
logger.Error(ctx,"delete test user",slog.Error(err))
2140-
return
2141-
}
2142-
expectedNotifications[notificationsLib.TemplateUserAccountDeleted]<-deleteTime
2143-
close(expectedNotifications[notificationsLib.TemplateUserAccountCreated])
2144-
close(expectedNotifications[notificationsLib.TemplateUserAccountDeleted])
2145-
}()
2063+
gotriggerUserNotifications(
2064+
ctx,
2065+
logger,
2066+
client,
2067+
me.OrganizationIDs[0],
2068+
ownerDialBarrier,
2069+
regularDialBarrier,
2070+
dialTimeout,
2071+
expectedNotifications,
2072+
)
21462073

21472074
th:=harness.NewTestHarness(timeoutStrategy.wrapStrategy(harness.ConcurrentExecutionStrategy{}),cleanupStrategy.toStrategy())
21482075

@@ -2446,6 +2373,101 @@ func parseTargetRange(name, targets string) (start, end int, err error) {
24462373
returnstart,end,nil
24472374
}
24482375

2376+
// triggerUserNotifications waits for all test users to connect,
2377+
// then creates and deletes a test user to trigger notification events for testing.
2378+
functriggerUserNotifications(
2379+
ctx context.Context,
2380+
logger slog.Logger,
2381+
client*codersdk.Client,
2382+
orgID uuid.UUID,
2383+
ownerDialBarrier*sync.WaitGroup,
2384+
regularDialBarrier*sync.WaitGroup,
2385+
dialTimeout time.Duration,
2386+
expectedNotificationsmap[uuid.UUID]chan time.Time,
2387+
) {
2388+
logger.Info(ctx,"waiting for owner users to connect")
2389+
2390+
// Wait for owner users to connect
2391+
ownerWaitCtx,cancel:=context.WithTimeout(ctx,dialTimeout+30*time.Second)
2392+
defercancel()
2393+
2394+
ownerDone:=make(chanstruct{})
2395+
gofunc() {
2396+
ownerDialBarrier.Wait()
2397+
close(ownerDone)
2398+
}()
2399+
2400+
select {
2401+
case<-ownerDone:
2402+
logger.Info(ctx,"all owner users connected")
2403+
case<-ownerWaitCtx.Done():
2404+
ifownerWaitCtx.Err()==context.DeadlineExceeded {
2405+
logger.Error(ctx,"timeout waiting for owner users to connect")
2406+
}else {
2407+
logger.Info(ctx,"context canceled while waiting for owner users")
2408+
}
2409+
return
2410+
}
2411+
2412+
// Wait for regular users to connect
2413+
logger.Info(ctx,"waiting for regular users to connect")
2414+
regularWaitCtx,cancel:=context.WithTimeout(ctx,dialTimeout+30*time.Second)
2415+
defercancel()
2416+
2417+
regularDone:=make(chanstruct{})
2418+
gofunc() {
2419+
regularDialBarrier.Wait()
2420+
close(regularDone)
2421+
}()
2422+
2423+
select {
2424+
case<-regularDone:
2425+
logger.Info(ctx,"all regular users connected")
2426+
case<-regularWaitCtx.Done():
2427+
ifregularWaitCtx.Err()==context.DeadlineExceeded {
2428+
logger.Error(ctx,"timeout waiting for regular users to connect")
2429+
}else {
2430+
logger.Info(ctx,"context canceled while waiting for regular users")
2431+
}
2432+
return
2433+
}
2434+
2435+
logger.Info(ctx,"all users connected, triggering notifications")
2436+
2437+
const (
2438+
triggerUsername="scaletest-trigger-user"
2439+
triggerEmail="scaletest-trigger@example.com"
2440+
)
2441+
2442+
logger.Info(ctx,"creating test user to test notifications",
2443+
slog.F("username",triggerUsername),
2444+
slog.F("email",triggerEmail),
2445+
slog.F("org_id",orgID))
2446+
2447+
createTime:=time.Now()
2448+
testUser,err:=client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
2449+
OrganizationIDs: []uuid.UUID{orgID},
2450+
Username:triggerUsername,
2451+
Email:triggerEmail,
2452+
Password:"test-password-123",
2453+
})
2454+
iferr!=nil {
2455+
logger.Error(ctx,"create test user",slog.Error(err))
2456+
return
2457+
}
2458+
expectedNotifications[notificationsLib.TemplateUserAccountCreated]<-createTime
2459+
2460+
deleteTime:=time.Now()
2461+
err=client.DeleteUser(ctx,testUser.ID)
2462+
iferr!=nil {
2463+
logger.Error(ctx,"delete test user",slog.Error(err))
2464+
return
2465+
}
2466+
expectedNotifications[notificationsLib.TemplateUserAccountDeleted]<-deleteTime
2467+
close(expectedNotifications[notificationsLib.TemplateUserAccountCreated])
2468+
close(expectedNotifications[notificationsLib.TemplateUserAccountDeleted])
2469+
}
2470+
24492471
funccreateWorkspaceAppConfig(client*codersdk.Client,appHost,appstring,workspace codersdk.Workspace,agent codersdk.WorkspaceAgent) (workspacetraffic.AppConfig,error) {
24502472
ifapp=="" {
24512473
return workspacetraffic.AppConfig{},nil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp