调整SetOptions的方式

This commit is contained in:
Yun
2025-11-21 15:54:49 +08:00
parent 04bdd98d6f
commit eeaa518fc3
17 changed files with 90 additions and 86 deletions
+13 -13
View File
@@ -17,7 +17,7 @@ func TestConcurrentSend(t *testing.T) {
ctx := context.Background()
// 配置SMTP客户端
_, err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
opt.Smtp = &interfaces.EmailConfigDataSmtp{
Host: "smtp.example.com",
Port: "587",
@@ -42,7 +42,7 @@ func TestConcurrentSend(t *testing.T) {
wg.Add(1)
go func(goroutineID int) {
defer wg.Done()
for j := 0; j < emailsPerGoroutine; j++ {
message := interfaces.Message{
To: []string{fmt.Sprintf("test%d_%d@example.com", goroutineID, j)},
@@ -55,7 +55,7 @@ func TestConcurrentSend(t *testing.T) {
if err != nil {
errors <- fmt.Errorf("goroutine %d, email %d: %w", goroutineID, j, err)
}
// 模拟发送时间
time.Sleep(10 * time.Millisecond)
}
@@ -88,7 +88,7 @@ func TestMemoryUsage(t *testing.T) {
smtpClient := smtp.NewSmtp()
ctx := context.Background()
_, err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
opt.Smtp = &interfaces.EmailConfigDataSmtp{
Host: "smtp.example.com",
Port: "587",
@@ -128,7 +128,7 @@ func TestConnectionReuse(t *testing.T) {
smtpClient := smtp.NewSmtp()
ctx := context.Background()
_, err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
opt.Smtp = &interfaces.EmailConfigDataSmtp{
Host: "smtp.example.com",
Port: "587",
@@ -168,7 +168,7 @@ func TestErrorRecovery(t *testing.T) {
smtpClient := smtp.NewSmtp()
ctx := context.Background()
_, err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
opt.Smtp = &interfaces.EmailConfigDataSmtp{
Host: "invalid-smtp-server.com", // 故意使用无效服务器
Port: "587",
@@ -187,7 +187,7 @@ func TestErrorRecovery(t *testing.T) {
}
start := time.Now()
// 这应该失败并触发重试机制
err = smtpClient.Send(ctx, message)
@@ -228,7 +228,7 @@ func TestLargeAttachment(t *testing.T) {
smtpClient := smtp.NewSmtp()
ctx := context.Background()
_, err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
opt.Smtp = &interfaces.EmailConfigDataSmtp{
Host: "smtp.example.com",
Port: "587",
@@ -282,11 +282,11 @@ func BenchmarkConcurrentEmailCreation(b *testing.B) {
// 配置创建基准测试
func BenchmarkSMTPConfiguration(b *testing.B) {
ctx := context.Background()
b.ResetTimer()
for i := 0; i < b.N; i++ {
smtpClient := smtp.NewSmtp()
_, err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
opt.Smtp = &interfaces.EmailConfigDataSmtp{
Host: "smtp.example.com",
Port: "587",
@@ -318,7 +318,7 @@ func TestLoadTesting(t *testing.T) {
smtpClient := smtp.NewSmtp()
ctx := context.Background()
_, err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
err := smtpClient.SetOption(ctx, func(opt *interfaces.Options) {
opt.Smtp = &interfaces.EmailConfigDataSmtp{
Host: "smtp.example.com",
Port: "587",
@@ -342,7 +342,7 @@ func TestLoadTesting(t *testing.T) {
wg.Add(1)
go func(emailID int) {
defer wg.Done()
// 获取信号量
semaphore <- struct{}{}
defer func() { <-semaphore }()
@@ -367,4 +367,4 @@ func TestLoadTesting(t *testing.T) {
t.Logf("- Concurrency: %d", concurrency)
t.Logf("- Duration: %v", duration)
t.Logf("- Throughput: %.2f emails/second", float64(totalEmails)/duration.Seconds())
}
}