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

Commitea15347

Browse files
committed
extract goroutine to separate function
1 parent1191ed2 commitea15347

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
@@ -1825,89 +1825,16 @@ func (r *RootCmd) scaletestNotifications() *serpent.Command {
18251825
configs=append(configs,config)
18261826
}
18271827

1828-
gofunc() {
1829-
logger.Info(ctx,"waiting for owner users to connect")
1830-
1831-
// Wait for owner users to connect
1832-
ownerWaitCtx,cancel:=context.WithTimeout(ctx,dialTimeout+30*time.Second)
1833-
defercancel()
1834-
1835-
ownerDone:=make(chanstruct{})
1836-
gofunc() {
1837-
ownerDialBarrier.Wait()
1838-
close(ownerDone)
1839-
}()
1840-
1841-
select {
1842-
case<-ownerDone:
1843-
logger.Info(ctx,"all owner users connected")
1844-
case<-ownerWaitCtx.Done():
1845-
ifownerWaitCtx.Err()==context.DeadlineExceeded {
1846-
logger.Error(ctx,"timeout waiting for owner users to connect")
1847-
}else {
1848-
logger.Info(ctx,"context canceled while waiting for owner users")
1849-
}
1850-
return
1851-
}
1852-
1853-
// Wait for regular users to connect
1854-
logger.Info(ctx,"waiting for regular users to connect")
1855-
regularWaitCtx,cancel:=context.WithTimeout(ctx,dialTimeout+30*time.Second)
1856-
defercancel()
1857-
1858-
regularDone:=make(chanstruct{})
1859-
gofunc() {
1860-
regularDialBarrier.Wait()
1861-
close(regularDone)
1862-
}()
1863-
1864-
select {
1865-
case<-regularDone:
1866-
logger.Info(ctx,"all regular users connected")
1867-
case<-regularWaitCtx.Done():
1868-
ifregularWaitCtx.Err()==context.DeadlineExceeded {
1869-
logger.Error(ctx,"timeout waiting for regular users to connect")
1870-
}else {
1871-
logger.Info(ctx,"context canceled while waiting for regular users")
1872-
}
1873-
return
1874-
}
1875-
1876-
logger.Info(ctx,"all users connected, triggering notifications")
1877-
1878-
const (
1879-
triggerUsername="scaletest-trigger-user"
1880-
triggerEmail="scaletest-trigger@example.com"
1881-
)
1882-
1883-
logger.Info(ctx,"creating test user to test notifications",
1884-
slog.F("username",triggerUsername),
1885-
slog.F("email",triggerEmail),
1886-
slog.F("org_id",me.OrganizationIDs[0]))
1887-
1888-
createTime:=time.Now()
1889-
testUser,err:=client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
1890-
OrganizationIDs: []uuid.UUID{me.OrganizationIDs[0]},
1891-
Username:triggerUsername,
1892-
Email:triggerEmail,
1893-
Password:"test-password-123",
1894-
})
1895-
iferr!=nil {
1896-
logger.Error(ctx,"create test user",slog.Error(err))
1897-
return
1898-
}
1899-
expectedNotifications[notificationsLib.TemplateUserAccountCreated]<-createTime
1900-
1901-
deleteTime:=time.Now()
1902-
err=client.DeleteUser(ctx,testUser.ID)
1903-
iferr!=nil {
1904-
logger.Error(ctx,"delete test user",slog.Error(err))
1905-
return
1906-
}
1907-
expectedNotifications[notificationsLib.TemplateUserAccountDeleted]<-deleteTime
1908-
close(expectedNotifications[notificationsLib.TemplateUserAccountCreated])
1909-
close(expectedNotifications[notificationsLib.TemplateUserAccountDeleted])
1910-
}()
1828+
gotriggerUserNotifications(
1829+
ctx,
1830+
logger,
1831+
client,
1832+
me.OrganizationIDs[0],
1833+
ownerDialBarrier,
1834+
regularDialBarrier,
1835+
dialTimeout,
1836+
expectedNotifications,
1837+
)
19111838

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

@@ -2211,6 +2138,101 @@ func parseTargetRange(name, targets string) (start, end int, err error) {
22112138
returnstart,end,nil
22122139
}
22132140

2141+
// triggerUserNotifications waits for all test users to connect,
2142+
// then creates and deletes a test user to trigger notification events for testing.
2143+
functriggerUserNotifications(
2144+
ctx context.Context,
2145+
logger slog.Logger,
2146+
client*codersdk.Client,
2147+
orgID uuid.UUID,
2148+
ownerDialBarrier*sync.WaitGroup,
2149+
regularDialBarrier*sync.WaitGroup,
2150+
dialTimeout time.Duration,
2151+
expectedNotificationsmap[uuid.UUID]chan time.Time,
2152+
) {
2153+
logger.Info(ctx,"waiting for owner users to connect")
2154+
2155+
// Wait for owner users to connect
2156+
ownerWaitCtx,cancel:=context.WithTimeout(ctx,dialTimeout+30*time.Second)
2157+
defercancel()
2158+
2159+
ownerDone:=make(chanstruct{})
2160+
gofunc() {
2161+
ownerDialBarrier.Wait()
2162+
close(ownerDone)
2163+
}()
2164+
2165+
select {
2166+
case<-ownerDone:
2167+
logger.Info(ctx,"all owner users connected")
2168+
case<-ownerWaitCtx.Done():
2169+
ifownerWaitCtx.Err()==context.DeadlineExceeded {
2170+
logger.Error(ctx,"timeout waiting for owner users to connect")
2171+
}else {
2172+
logger.Info(ctx,"context canceled while waiting for owner users")
2173+
}
2174+
return
2175+
}
2176+
2177+
// Wait for regular users to connect
2178+
logger.Info(ctx,"waiting for regular users to connect")
2179+
regularWaitCtx,cancel:=context.WithTimeout(ctx,dialTimeout+30*time.Second)
2180+
defercancel()
2181+
2182+
regularDone:=make(chanstruct{})
2183+
gofunc() {
2184+
regularDialBarrier.Wait()
2185+
close(regularDone)
2186+
}()
2187+
2188+
select {
2189+
case<-regularDone:
2190+
logger.Info(ctx,"all regular users connected")
2191+
case<-regularWaitCtx.Done():
2192+
ifregularWaitCtx.Err()==context.DeadlineExceeded {
2193+
logger.Error(ctx,"timeout waiting for regular users to connect")
2194+
}else {
2195+
logger.Info(ctx,"context canceled while waiting for regular users")
2196+
}
2197+
return
2198+
}
2199+
2200+
logger.Info(ctx,"all users connected, triggering notifications")
2201+
2202+
const (
2203+
triggerUsername="scaletest-trigger-user"
2204+
triggerEmail="scaletest-trigger@example.com"
2205+
)
2206+
2207+
logger.Info(ctx,"creating test user to test notifications",
2208+
slog.F("username",triggerUsername),
2209+
slog.F("email",triggerEmail),
2210+
slog.F("org_id",orgID))
2211+
2212+
createTime:=time.Now()
2213+
testUser,err:=client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
2214+
OrganizationIDs: []uuid.UUID{orgID},
2215+
Username:triggerUsername,
2216+
Email:triggerEmail,
2217+
Password:"test-password-123",
2218+
})
2219+
iferr!=nil {
2220+
logger.Error(ctx,"create test user",slog.Error(err))
2221+
return
2222+
}
2223+
expectedNotifications[notificationsLib.TemplateUserAccountCreated]<-createTime
2224+
2225+
deleteTime:=time.Now()
2226+
err=client.DeleteUser(ctx,testUser.ID)
2227+
iferr!=nil {
2228+
logger.Error(ctx,"delete test user",slog.Error(err))
2229+
return
2230+
}
2231+
expectedNotifications[notificationsLib.TemplateUserAccountDeleted]<-deleteTime
2232+
close(expectedNotifications[notificationsLib.TemplateUserAccountCreated])
2233+
close(expectedNotifications[notificationsLib.TemplateUserAccountDeleted])
2234+
}
2235+
22142236
funccreateWorkspaceAppConfig(client*codersdk.Client,appHost,appstring,workspace codersdk.Workspace,agent codersdk.WorkspaceAgent) (workspacetraffic.AppConfig,error) {
22152237
ifapp=="" {
22162238
return workspacetraffic.AppConfig{},nil

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp