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 imapsql
20
21import (
22	"flag"
23	"strconv"
24	"testing"
25	"time"
26
27	imapsql "github.com/foxcpp/go-imap-sql"
28	"github.com/foxcpp/maddy/internal/testutils"
29)
30
31var (
32	testDB      string
33	testDSN     string
34	testFsstore string
35)
36
37func init() {
38	flag.StringVar(&testDB, "sql.testdb", "", "Database to use for storage/sql benchmarks")
39	flag.StringVar(&testDSN, "sql.testdsn", "", "DSN to use for storage/sql benchmarks")
40	flag.StringVar(&testFsstore, "sql.testfsstore", "", "fsstore location to use for storage/sql benchmarks")
41}
42
43func createTestDB(tb testing.TB, compAlgo string) *Storage {
44	if testDB == "" || testDSN == "" || testFsstore == "" {
45		tb.Skip("-sql.testdb, -sql.testdsn and -sql.testfsstore should be specified to run this benchmark")
46	}
47
48	db, err := imapsql.New(testDB, testDSN, &imapsql.FSStore{Root: testFsstore}, imapsql.Opts{
49		CompressAlgo: compAlgo,
50	})
51	if err != nil {
52		tb.Fatal(err)
53	}
54	return &Storage{
55		Back: db,
56	}
57}
58
59func BenchmarkStorage_Delivery(b *testing.B) {
60	randomKey := "rcpt-" + strconv.FormatInt(time.Now().UnixNano(), 10) + "@example.org"
61
62	be := createTestDB(b, "")
63	if err := be.CreateIMAPAcct(randomKey); err != nil {
64		b.Fatal(err)
65	}
66
67	testutils.BenchDelivery(b, be, "sender@example.org", []string{randomKey})
68}
69
70func BenchmarkStorage_DeliveryLZ4(b *testing.B) {
71	randomKey := "rcpt-" + strconv.FormatInt(time.Now().UnixNano(), 10) + "@example.org"
72
73	be := createTestDB(b, "lz4")
74	if err := be.CreateIMAPAcct(randomKey); err != nil {
75		b.Fatal(err)
76	}
77
78	testutils.BenchDelivery(b, be, "sender@example.org", []string{randomKey})
79}
80
81func BenchmarkStorage_DeliveryZstd(b *testing.B) {
82	randomKey := "rcpt-" + strconv.FormatInt(time.Now().UnixNano(), 10) + "@example.org"
83
84	be := createTestDB(b, "zstd")
85	if err := be.CreateIMAPAcct(randomKey); err != nil {
86		b.Fatal(err)
87	}
88
89	testutils.BenchDelivery(b, be, "sender@example.org", []string{randomKey})
90}