mirror of https://github.com/gophish/gophish
Adding benchmarks for maillog.Generate. Ref #1726
parent
947bb4ccba
commit
0620671de6
|
@ -195,6 +195,20 @@ func setupCampaignDependencies(b *testing.B, size int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setupCampaign sets up the campaign dependencies as well as posting the
|
||||||
|
// actual campaign
|
||||||
|
func setupCampaign(b *testing.B, size int) Campaign {
|
||||||
|
setupCampaignDependencies(b, size)
|
||||||
|
campaign := Campaign{Name: "Test campaign"}
|
||||||
|
campaign.UserId = 1
|
||||||
|
campaign.Template = Template{Name: "Test Template"}
|
||||||
|
campaign.Page = Page{Name: "Test Page"}
|
||||||
|
campaign.SMTP = SMTP{Name: "Test Page"}
|
||||||
|
campaign.Groups = []Group{Group{Name: "Test Group"}}
|
||||||
|
PostCampaign(&campaign, 1)
|
||||||
|
return campaign
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkCampaign100(b *testing.B) {
|
func BenchmarkCampaign100(b *testing.B) {
|
||||||
setupBenchmark(b)
|
setupBenchmark(b)
|
||||||
setupCampaignDependencies(b, 100)
|
setupCampaignDependencies(b, 100)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gophish/gophish/config"
|
"github.com/gophish/gophish/config"
|
||||||
|
@ -322,3 +323,63 @@ func (s *ModelsSuite) TestMailLogGenerateEmptySubject(ch *check.C) {
|
||||||
got := s.emailFromFirstMailLog(campaign, ch)
|
got := s.emailFromFirstMailLog(campaign, ch)
|
||||||
ch.Assert(got.Subject, check.Equals, expected.Subject)
|
ch.Assert(got.Subject, check.Equals, expected.Subject)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkMailLogGenerate100(b *testing.B) {
|
||||||
|
setupBenchmark(b)
|
||||||
|
campaign := setupCampaign(b, 100)
|
||||||
|
ms, err := GetMailLogsByCampaign(campaign.Id)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("error getting maillogs for campaign: %v", err)
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
msg := gomail.NewMessage()
|
||||||
|
ms[0].Generate(msg)
|
||||||
|
}
|
||||||
|
tearDownBenchmark(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkMailLogGenerate1000(b *testing.B) {
|
||||||
|
setupBenchmark(b)
|
||||||
|
campaign := setupCampaign(b, 1000)
|
||||||
|
ms, err := GetMailLogsByCampaign(campaign.Id)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("error getting maillogs for campaign: %v", err)
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
msg := gomail.NewMessage()
|
||||||
|
ms[0].Generate(msg)
|
||||||
|
}
|
||||||
|
tearDownBenchmark(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkMailLogGenerate5000(b *testing.B) {
|
||||||
|
setupBenchmark(b)
|
||||||
|
campaign := setupCampaign(b, 5000)
|
||||||
|
ms, err := GetMailLogsByCampaign(campaign.Id)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("error getting maillogs for campaign: %v", err)
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
msg := gomail.NewMessage()
|
||||||
|
ms[0].Generate(msg)
|
||||||
|
}
|
||||||
|
tearDownBenchmark(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkMailLogGenerate10000(b *testing.B) {
|
||||||
|
setupBenchmark(b)
|
||||||
|
campaign := setupCampaign(b, 10000)
|
||||||
|
ms, err := GetMailLogsByCampaign(campaign.Id)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("error getting maillogs for campaign: %v", err)
|
||||||
|
}
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
msg := gomail.NewMessage()
|
||||||
|
ms[0].Generate(msg)
|
||||||
|
}
|
||||||
|
tearDownBenchmark(b)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue