Skip to content

Commit

Permalink
feat: stress for helm testing
Browse files Browse the repository at this point in the history
  • Loading branch information
fadyat committed Nov 11, 2023
1 parent a0580fa commit b18a8fc
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
go-version: '1.21'
- uses: actions/checkout@v3
- uses: ko-build/setup-ko@v0.6
- run: ko build --platform=linux/amd64 --bare ./cmd/...
- run: ko build --platform=linux/amd64 --bare ./cmd/erida/...
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ ifneq (,$(wildcard ./.env))
export
endif

include helm/Makefile

run:
@go run ./cmd/main.go
@go run ./cmd/erida/main.go

stress:
@go run ./cmd/stress/main.go

integration:
@go test -v ./... -tags=integration
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Configuring Erida is a breeze. All you need to do is set the following environme
- `SMTP_HOST`: SMTP server host
- `SMTP_PORT`: SMTP server port
- `SMTP_USER`: SMTP server username
- `SMTP_PASSWORD`: SMTP server password
- `SMTP_PASS`: SMTP server password
- `SLACK_TOKEN`: Slack bot token
- `SMTP_TLS` (Optional, default: true): Enable or disable Start TLS usage

Expand Down
File renamed without changes.
File renamed without changes.
61 changes: 61 additions & 0 deletions cmd/stress/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package main

import (
"fmt"
"github.com/emersion/go-smtp"
"log/slog"
"os"
"strings"
"sync"
"time"
)

var (
eridaAddr = os.Getenv("ERIDA_ADDR")
from = os.Getenv("ERIDA_FROM")
to = strings.Split(os.Getenv("ERIDA_TO"), ",")
bodyPattern = os.Getenv("ERIDA_BODY_PATTERN")
)

// following code is a stress test for erida
// it will send 10 messages to erida server
//
// they will be launched in the same cluster
func main() {
time.Sleep(5 * time.Second)

var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)

go func(i int) {
defer wg.Done()

issueRequest(i)
}(i)
}

wg.Wait()
}

func issueRequest(reqNumber int) {
erida, err := smtp.Dial(eridaAddr)
if err != nil {
slog.Error("failed to dial erida server", "error", err)
return
}

defer func() {
if err = erida.Quit(); err != nil {
slog.Error("failed to quit erida server", "error", err)
}
}()

var body = strings.NewReader(fmt.Sprintf(bodyPattern, reqNumber))
if err = erida.SendMail(from, to, body); err != nil {
slog.Error("failed to send email", "error", err)
return
}

slog.Info("email sent", "reqNumber", reqNumber)
}
2 changes: 1 addition & 1 deletion internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "fmt"

type Config struct {
RelayHost string `env:"SERVER_HOST" env-default:"localhost"`
RelayPort string `env:"SERVER_PORT" env-default:"1025"`
RelayPort string `env:"SERVER_PORT" env-default:"25"`
Host string `env:"SMTP_HOST" env-default:"smtp.gmail.com"`
Port string `env:"SMTP_PORT" env-default:"587"`
User string `env:"SMTP_USER"`
Expand Down

0 comments on commit b18a8fc

Please sign in to comment.