Skip to content

Commit

Permalink
feat(GODT-1570): Add status benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
LBeernaertProton authored and jameshoulahan committed Sep 19, 2022
1 parent cf9f44a commit 5e12e14
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions benchmarks/gluon_bench/imap_benchmarks/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package imap_benchmarks

import (
"context"
"flag"
"net"

"github.com/ProtonMail/gluon/benchmarks/gluon_bench/benchmark"
"github.com/emersion/go-imap"
"github.com/emersion/go-imap/client"
)

var statusCallCountFlag = flag.Uint("imap-status-count", 1000, "Number of times to call status.")

type Status struct {
*stateTracker
}

func NewStatus() benchmark.Benchmark {
return NewIMAPBenchmarkRunner(&Status{stateTracker: newStateTracker()})
}

func (*Status) Name() string {
return "imap-status"
}

func (s *Status) Setup(ctx context.Context, addr net.Addr) error {
return WithClient(addr, func(cl *client.Client) error {
if _, err := s.createAndFillRandomMBox(cl); err != nil {
return err
}

return nil
})
}

func (s *Status) TearDown(ctx context.Context, addr net.Addr) error {
return s.cleanupWithAddr(addr)
}

func (s *Status) Run(ctx context.Context, addr net.Addr) error {
RunParallelClientsWithMailbox(addr, s.MBoxes[0], *fetchReadOnly, func(cl *client.Client, index uint) {
for i := uint(0); i < *statusCallCountFlag; i++ {
_, err := cl.Status(s.MBoxes[0], []imap.StatusItem{imap.StatusRecent, imap.StatusMessages, imap.StatusRecent, imap.StatusUnseen, imap.StatusUidNext, imap.StatusUidValidity})
if err != nil {
panic(err)
}
}
})

return nil
}

func init() {
benchmark.RegisterBenchmark(NewStatus())
}

0 comments on commit 5e12e14

Please sign in to comment.