1/*2Maddy Mail Server - Composable all-in-one email server.3Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors45This program is free software: you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation, either version 3 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program. If not, see <https://www.gnu.org/licenses/>.17*/1819package msgpipeline2021import (22 "strconv"23 "testing"2425 "github.com/foxcpp/maddy/framework/module"26 "github.com/foxcpp/maddy/internal/testutils"27)2829func 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 }}4041 testutils.BenchDelivery(b, &d, "sender@example.org", []string{"rcpt-X@example.org"})42}4344func 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 }5152 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 }}6364 testutils.BenchDelivery(b, &d, "sender@example.org", []string{"rcpt-X@example.org"})65 })66 }6768 testWithCount(5)69 testWithCount(10)70 testWithCount(15)71}7273func 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 }8081 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 }}9091 testutils.BenchDelivery(b, &d, "sender@example.org", []string{"rcpt-X@example.org"})92 })93 }9495 testWithCount(5)96 testWithCount(10)97 testWithCount(15)98}