1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
package tests
import (
"fmt"
"testing"
goimap "github.com/emersion/go-imap"
"github.com/emersion/go-imap/client"
"github.com/stretchr/testify/require"
)
func BenchmarkBigMailboxStatus(b *testing.B) {
runOneToOneTestWithAuth(b, defaultServerOptions(b), func(c *testConnection, s *testSession) {
mboxID := s.mailboxCreated("user", []string{"mbox"})
ids := s.batchMessageCreated("user", mboxID, 32515, func(n int) ([]byte, []string) {
return []byte(fmt.Sprintf(`To: %v@pm.me`, n)), []string{}
})
b.Run("status", func(b *testing.B) {
c.Cf(`A001 STATUS %v (MESSAGES)`, "mbox").Sx(fmt.Sprintf(`MESSAGES %v`, len(ids))).OK(`A001`)
})
})
}
func BenchmarkBigMailboxFetchSequence(b *testing.B) {
runOneToOneTestClientWithAuth(b, defaultServerOptions(b), func(client *client.Client, s *testSession) {
mboxID := s.mailboxCreated("user", []string{"mbox"})
ids := s.batchMessageCreated("user", mboxID, 128515, func(n int) ([]byte, []string) {
return []byte(fmt.Sprintf(`To: %v@pm.me`, n)), []string{}
})
_, err := client.Select("mbox", false)
require.NoError(b, err)
fetchResult := newFetchCommand(b, client).withItems(goimap.FetchAll).fetch("1:*")
if len(fetchResult.messages) != len(ids) {
panic("Fetch failed")
}
})
}
func BenchmarkBigMailboxFetchUID(b *testing.B) {
runOneToOneTestClientWithAuth(b, defaultServerOptions(b), func(client *client.Client, s *testSession) {
mboxID := s.mailboxCreated("user", []string{"mbox"})
ids := s.batchMessageCreated("user", mboxID, 128515, func(n int) ([]byte, []string) {
return []byte(fmt.Sprintf(`To: %v@pm.me`, n)), []string{}
})
_, err := client.Select("mbox", false)
require.NoError(b, err)
fetchResult := newFetchCommand(b, client).withItems(goimap.FetchAll).fetchUid("1:*")
if len(fetchResult.messages) != len(ids) {
panic("Fetch failed")
}
})
}
func BenchmarkListManyMailboxes(b *testing.B) {
runOneToOneTestClientWithAuth(b, defaultServerOptions(b), func(client *client.Client, s *testSession) {
s.batchMailboxCreated("user", 64515, func(i int) string { return fmt.Sprintf("mbox_%v", i) })
listMailboxesClient(b, client, "", "*")
})
}
|