-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(GODT-1570): Add status benchmark
- Loading branch information
1 parent
cf9f44a
commit 5e12e14
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |