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 imapsql2021import (22 "flag"23 "strconv"24 "testing"25 "time"2627 imapsql "github.com/foxcpp/go-imap-sql"28 "github.com/foxcpp/maddy/internal/testutils"29)3031var (32 testDB string33 testDSN string34 testFsstore string35)3637func 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}4243func 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 }4748 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}5859func BenchmarkStorage_Delivery(b *testing.B) {60 randomKey := "rcpt-" + strconv.FormatInt(time.Now().UnixNano(), 10) + "@example.org"6162 be := createTestDB(b, "")63 if err := be.CreateIMAPAcct(randomKey); err != nil {64 b.Fatal(err)65 }6667 testutils.BenchDelivery(b, be, "sender@example.org", []string{randomKey})68}6970func BenchmarkStorage_DeliveryLZ4(b *testing.B) {71 randomKey := "rcpt-" + strconv.FormatInt(time.Now().UnixNano(), 10) + "@example.org"7273 be := createTestDB(b, "lz4")74 if err := be.CreateIMAPAcct(randomKey); err != nil {75 b.Fatal(err)76 }7778 testutils.BenchDelivery(b, be, "sender@example.org", []string{randomKey})79}8081func BenchmarkStorage_DeliveryZstd(b *testing.B) {82 randomKey := "rcpt-" + strconv.FormatInt(time.Now().UnixNano(), 10) + "@example.org"8384 be := createTestDB(b, "zstd")85 if err := be.CreateIMAPAcct(randomKey); err != nil {86 b.Fatal(err)87 }8889 testutils.BenchDelivery(b, be, "sender@example.org", []string{randomKey})90}