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

Commitf172a54

Browse files
committed
Extract scaletestSMTP to separate file
1 parent06b27d2 commitf172a54

File tree

2 files changed

+111
-96
lines changed

2 files changed

+111
-96
lines changed

‎cli/exp_scaletest.go‎

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import (
4242
"github.com/coder/coder/v2/scaletest/loadtestutil"
4343
"github.com/coder/coder/v2/scaletest/notifications"
4444
"github.com/coder/coder/v2/scaletest/reconnectingpty"
45-
"github.com/coder/coder/v2/scaletest/smtpmock"
4645
"github.com/coder/coder/v2/scaletest/workspacebuild"
4746
"github.com/coder/coder/v2/scaletest/workspacetraffic"
4847
"github.com/coder/coder/v2/scaletest/workspaceupdates"
@@ -2176,101 +2175,6 @@ func (r *RootCmd) scaletestNotifications() *serpent.Command {
21762175
returncmd
21772176
}
21782177

2179-
func (*RootCmd)scaletestSMTP()*serpent.Command {
2180-
var (
2181-
hostAddressstring
2182-
smtpPortint64
2183-
apiPortint64
2184-
purgeAtCountint64
2185-
)
2186-
cmd:=&serpent.Command{
2187-
Use:"smtp",
2188-
Short:"Start a mock SMTP server for testing",
2189-
Long:`Start a mock SMTP server with an HTTP API server that can be used to purge
2190-
messages and get messages by email.`,
2191-
Handler:func(inv*serpent.Invocation)error {
2192-
ctx:=inv.Context()
2193-
notifyCtx,stop:=signal.NotifyContext(ctx,StopSignals...)
2194-
deferstop()
2195-
ctx=notifyCtx
2196-
2197-
logger:=slog.Make(sloghuman.Sink(inv.Stderr)).Leveled(slog.LevelInfo)
2198-
srv:=smtpmock.New(smtpmock.Config{
2199-
HostAddress:hostAddress,
2200-
SMTPPort:int(smtpPort),
2201-
APIPort:int(apiPort),
2202-
Logger:logger,
2203-
})
2204-
2205-
iferr:=srv.Start(ctx);err!=nil {
2206-
returnxerrors.Errorf("start mock SMTP server: %w",err)
2207-
}
2208-
deferfunc() {
2209-
_=srv.Stop()
2210-
}()
2211-
2212-
_,_=fmt.Fprintf(inv.Stdout,"Mock SMTP server started on %s\n",srv.SMTPAddress())
2213-
_,_=fmt.Fprintf(inv.Stdout,"HTTP API server started on %s\n",srv.APIAddress())
2214-
ifpurgeAtCount>0 {
2215-
_,_=fmt.Fprintf(inv.Stdout," Auto-purge when message count reaches %d\n",purgeAtCount)
2216-
}
2217-
2218-
ticker:=time.NewTicker(10*time.Second)
2219-
deferticker.Stop()
2220-
2221-
for {
2222-
select {
2223-
case<-ctx.Done():
2224-
_,_=fmt.Fprintf(inv.Stdout,"\nTotal messages received since last purge: %d\n",srv.MessageCount())
2225-
returnnil
2226-
case<-ticker.C:
2227-
count:=srv.MessageCount()
2228-
ifcount>0 {
2229-
_,_=fmt.Fprintf(inv.Stdout,"Messages received: %d\n",count)
2230-
}
2231-
2232-
ifpurgeAtCount>0&&int64(count)>=purgeAtCount {
2233-
_,_=fmt.Fprintf(inv.Stdout,"Message count (%d) reached threshold (%d). Purging...\n",count,purgeAtCount)
2234-
srv.Purge()
2235-
continue
2236-
}
2237-
}
2238-
}
2239-
},
2240-
}
2241-
2242-
cmd.Options= []serpent.Option{
2243-
{
2244-
Flag:"host-address",
2245-
Env:"CODER_SCALETEST_SMTP_HOST",
2246-
Default:"localhost",
2247-
Description:"Host to bind the mock SMTP and API servers.",
2248-
Value:serpent.StringOf(&hostAddress),
2249-
},
2250-
{
2251-
Flag:"smtp-port",
2252-
Env:"CODER_SCALETEST_SMTP_PORT",
2253-
Description:"Port for the mock SMTP server. Uses a random port if not specified.",
2254-
Value:serpent.Int64Of(&smtpPort),
2255-
},
2256-
{
2257-
Flag:"api-port",
2258-
Env:"CODER_SCALETEST_SMTP_API_PORT",
2259-
Description:"Port for the HTTP API server. Uses a random port if not specified.",
2260-
Value:serpent.Int64Of(&apiPort),
2261-
},
2262-
{
2263-
Flag:"purge-at-count",
2264-
Env:"CODER_SCALETEST_SMTP_PURGE_AT_COUNT",
2265-
Default:"100000",
2266-
Description:"Maximum number of messages to keep before auto-purging. Set to 0 to disable.",
2267-
Value:serpent.Int64Of(&purgeAtCount),
2268-
},
2269-
}
2270-
2271-
returncmd
2272-
}
2273-
22742178
typerunnableTraceWrapperstruct {
22752179
tracer trace.Tracer
22762180
spanNamestring

‎cli/exp_scaletest_smtp.go‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//go:build !slim
2+
3+
package cli
4+
5+
import (
6+
"fmt"
7+
"os/signal"
8+
"time"
9+
10+
"golang.org/x/xerrors"
11+
12+
"cdr.dev/slog"
13+
"cdr.dev/slog/sloggers/sloghuman"
14+
"github.com/coder/coder/v2/scaletest/smtpmock"
15+
"github.com/coder/serpent"
16+
)
17+
18+
func (*RootCmd)scaletestSMTP()*serpent.Command {
19+
var (
20+
hostAddressstring
21+
smtpPortint64
22+
apiPortint64
23+
purgeAtCountint64
24+
)
25+
cmd:=&serpent.Command{
26+
Use:"smtp",
27+
Short:"Start a mock SMTP server for testing",
28+
Long:`Start a mock SMTP server with an HTTP API server that can be used to purge
29+
messages and get messages by email.`,
30+
Handler:func(inv*serpent.Invocation)error {
31+
ctx:=inv.Context()
32+
notifyCtx,stop:=signal.NotifyContext(ctx,StopSignals...)
33+
deferstop()
34+
ctx=notifyCtx
35+
36+
logger:=slog.Make(sloghuman.Sink(inv.Stderr)).Leveled(slog.LevelInfo)
37+
srv:=smtpmock.New(smtpmock.Config{
38+
HostAddress:hostAddress,
39+
SMTPPort:int(smtpPort),
40+
APIPort:int(apiPort),
41+
Logger:logger,
42+
})
43+
44+
iferr:=srv.Start(ctx);err!=nil {
45+
returnxerrors.Errorf("start mock SMTP server: %w",err)
46+
}
47+
deferfunc() {
48+
_=srv.Stop()
49+
}()
50+
51+
_,_=fmt.Fprintf(inv.Stdout,"Mock SMTP server started on %s\n",srv.SMTPAddress())
52+
_,_=fmt.Fprintf(inv.Stdout,"HTTP API server started on %s\n",srv.APIAddress())
53+
ifpurgeAtCount>0 {
54+
_,_=fmt.Fprintf(inv.Stdout," Auto-purge when message count reaches %d\n",purgeAtCount)
55+
}
56+
57+
ticker:=time.NewTicker(10*time.Second)
58+
deferticker.Stop()
59+
60+
for {
61+
select {
62+
case<-ctx.Done():
63+
_,_=fmt.Fprintf(inv.Stdout,"\nTotal messages received since last purge: %d\n",srv.MessageCount())
64+
returnnil
65+
case<-ticker.C:
66+
count:=srv.MessageCount()
67+
ifcount>0 {
68+
_,_=fmt.Fprintf(inv.Stdout,"Messages received: %d\n",count)
69+
}
70+
71+
ifpurgeAtCount>0&&int64(count)>=purgeAtCount {
72+
_,_=fmt.Fprintf(inv.Stdout,"Message count (%d) reached threshold (%d). Purging...\n",count,purgeAtCount)
73+
srv.Purge()
74+
continue
75+
}
76+
}
77+
}
78+
},
79+
}
80+
81+
cmd.Options= []serpent.Option{
82+
{
83+
Flag:"host-address",
84+
Env:"CODER_SCALETEST_SMTP_HOST_ADDRESS",
85+
Default:"localhost",
86+
Description:"Host address to bind the mock SMTP and API servers.",
87+
Value:serpent.StringOf(&hostAddress),
88+
},
89+
{
90+
Flag:"smtp-port",
91+
Env:"CODER_SCALETEST_SMTP_PORT",
92+
Description:"Port for the mock SMTP server. Uses a random port if not specified.",
93+
Value:serpent.Int64Of(&smtpPort),
94+
},
95+
{
96+
Flag:"api-port",
97+
Env:"CODER_SCALETEST_SMTP_API_PORT",
98+
Description:"Port for the HTTP API server. Uses a random port if not specified.",
99+
Value:serpent.Int64Of(&apiPort),
100+
},
101+
{
102+
Flag:"purge-at-count",
103+
Env:"CODER_SCALETEST_SMTP_PURGE_AT_COUNT",
104+
Default:"100000",
105+
Description:"Maximum number of messages to keep before auto-purging. Set to 0 to disable.",
106+
Value:serpent.Int64Of(&purgeAtCount),
107+
},
108+
}
109+
110+
returncmd
111+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp