Skip to content

feat(cli): add mock SMTP server for testing scaletest notifications#20221

Merged
kacpersaw merged 9 commits into
mainfrom
kacpersaw/scaletest-smtp-mock-server
Oct 22, 2025
Merged

feat(cli): add mock SMTP server for testing scaletest notifications#20221
kacpersaw merged 9 commits into
mainfrom
kacpersaw/scaletest-smtp-mock-server

Conversation

@kacpersaw
Copy link
Copy Markdown

@kacpersaw kacpersaw commented Oct 8, 2025

This PR adds a fake SMTP server for scale testing. It collects emails sent during tests, which you can then check using the HTTP API.

Changes

  • Added mock SMTP server
  • Added coder scaletest smtp CLI command
  • Implemented HTTP API endpoints to retrieve messages by email
  • Added auto-purge to prevent memory issues

HTTP API Endpoints

  • GET /messages?email=<email> – Get messages sent to an email address
  • POST /purge – Clear all messages from memory

The HTTP API parses raw email messages to extract the date, subject, and notification ID.

Notification IDs are sent in emails like this:

<p>
  <a href="http://127.0.0.1:3000/settings/notifications?disabled=4e19c0ac-94e1-4532-9515-d1801aa283b2"
     style="color: #2563eb; text-decoration: none;">
    Stop receiving emails like this
  </a>
</p>

CLI

coder scaletest smtp --host localhost --port 33199 --api-port 8080 --purge-at-count 1000

Flags:

  • --host: Host for the mock SMTP and API server (default: localhost)
  • --port: Port for the mock SMTP server (random if not specified)
  • --api-port: Port for the HTTP API server (random if not specified)
  • --purge-at-count: Max number of messages before auto-purging (default: 100000)

Copy link
Copy Markdown
Author

@kacpersaw kacpersaw marked this pull request as ready for review October 8, 2025 15:35
@kacpersaw kacpersaw requested a review from spikecurtis October 8, 2025 15:35
@kacpersaw kacpersaw force-pushed the kacpersaw/scaletest-smtp-mock-server branch from 5830a76 to 20790fc Compare October 8, 2025 16:02
if err := s.smtpServer.Start(); err != nil {
return xerrors.Errorf("start SMTP server: %w", err)
}
s.smtpPort = s.smtpServer.PortNumber()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are doing this so that you can leave the port initially set to 0 and then later query the running port. It feels like a sharp edge, though, that s.SMTPAddress() will show you a 0 port until you start the server. Is there any reason why we don't want to just start the server immediately on New()?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of allocating ports in New(). IMO It should only be responsible for initialization. We could remove New() and let Start() handle init instead, since we don't do any complicated stuff in there. WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like:

srv := new(Server)
err = srv.Start(ctx, config)

I think that's fine.

Comment thread scaletest/smtpmock/server.go Outdated
Comment thread scaletest/smtpmock/server.go Outdated
Comment thread scaletest/smtpmock/server.go Outdated
Comment thread scaletest/smtpmock/server.go Outdated
Comment thread cli/exp_scaletest.go Outdated
Comment thread scaletest/smtpmock/server.go Outdated
Comment thread scaletest/smtpmock/server.go Outdated
Comment thread cli/exp_scaletest.go Outdated
Comment thread cli/exp_scaletest.go Outdated
@kacpersaw kacpersaw requested a review from spikecurtis October 21, 2025 06:58
Copy link
Copy Markdown
Contributor

@spikecurtis spikecurtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion inline, but I don't need to review again.

Comment thread scaletest/smtpmock/server.go Outdated
// Notification ID is present in the email footer like this
// <p><a href=3D"http://127.0.0.1:3000/settings/notifications?disabled=3D
// =3D4e19c0ac-94e1-4532-9515-d1801aa283b2" style=3D"color: #2563eb; text-deco=
// ration: none;">Stop receiving emails like this</a></p>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is still in quotedprintable encoding, which makes it harder to understand.

@kacpersaw kacpersaw force-pushed the kacpersaw/scaletest-smtp-mock-server branch from dc3c69d to adc1c9f Compare October 21, 2025 13:50
Copy link
Copy Markdown
Author

kacpersaw commented Oct 22, 2025

Merge activity

  • Oct 22, 9:14 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Oct 22, 9:14 AM UTC: @kacpersaw merged this pull request with Graphite.

@kacpersaw kacpersaw merged commit 7bbeef4 into main Oct 22, 2025
26 checks passed
@kacpersaw kacpersaw deleted the kacpersaw/scaletest-smtp-mock-server branch October 22, 2025 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants