maddy

Fork https://github.com/foxcpp/maddy

git clone git://git.lin.moe/go/maddy.git

 1/*
 2Maddy Mail Server - Composable all-in-one email server.
 3Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors
 4
 5This program is free software: you can redistribute it and/or modify
 6it under the terms of the GNU General Public License as published by
 7the Free Software Foundation, either version 3 of the License, or
 8(at your option) any later version.
 9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program.  If not, see <https://www.gnu.org/licenses/>.
17*/
18
19package msgpipeline
20
21import (
22	"strconv"
23	"testing"
24
25	"github.com/foxcpp/maddy/framework/module"
26	"github.com/foxcpp/maddy/internal/testutils"
27)
28
29func BenchmarkMsgPipelineSimple(b *testing.B) {
30	target := testutils.Target{InstName: "test_target", DiscardMessages: true}
31	d := MsgPipeline{msgpipelineCfg: msgpipelineCfg{
32		perSource: map[string]sourceBlock{},
33		defaultSource: sourceBlock{
34			perRcpt: map[string]*rcptBlock{},
35			defaultRcpt: &rcptBlock{
36				targets: []module.DeliveryTarget{&target},
37			},
38		},
39	}}
40
41	testutils.BenchDelivery(b, &d, "sender@example.org", []string{"rcpt-X@example.org"})
42}
43
44func BenchmarkMsgPipelineGlobalChecks(b *testing.B) {
45	testWithCount := func(checksCount int) {
46		b.Run(strconv.Itoa(checksCount), func(b *testing.B) {
47			checks := make([]module.Check, 0, checksCount)
48			for i := 0; i < checksCount; i++ {
49				checks = append(checks, &testutils.Check{InstName: "check_" + strconv.Itoa(i)})
50			}
51
52			target := testutils.Target{InstName: "test_target", DiscardMessages: true}
53			d := MsgPipeline{msgpipelineCfg: msgpipelineCfg{
54				globalChecks: checks,
55				perSource:    map[string]sourceBlock{},
56				defaultSource: sourceBlock{
57					perRcpt: map[string]*rcptBlock{},
58					defaultRcpt: &rcptBlock{
59						targets: []module.DeliveryTarget{&target},
60					},
61				},
62			}}
63
64			testutils.BenchDelivery(b, &d, "sender@example.org", []string{"rcpt-X@example.org"})
65		})
66	}
67
68	testWithCount(5)
69	testWithCount(10)
70	testWithCount(15)
71}
72
73func BenchmarkMsgPipelineTargets(b *testing.B) {
74	testWithCount := func(targetCount int) {
75		b.Run(strconv.Itoa(targetCount), func(b *testing.B) {
76			targets := make([]module.DeliveryTarget, 0, targetCount)
77			for i := 0; i < targetCount; i++ {
78				targets = append(targets, &testutils.Target{InstName: "target_" + strconv.Itoa(i), DiscardMessages: true})
79			}
80
81			d := MsgPipeline{msgpipelineCfg: msgpipelineCfg{
82				perSource: map[string]sourceBlock{},
83				defaultSource: sourceBlock{
84					perRcpt: map[string]*rcptBlock{},
85					defaultRcpt: &rcptBlock{
86						targets: targets,
87					},
88				},
89			}}
90
91			testutils.BenchDelivery(b, &d, "sender@example.org", []string{"rcpt-X@example.org"})
92		})
93	}
94
95	testWithCount(5)
96	testWithCount(10)
97	testWithCount(15)
98}