Skip to content

Commit

Permalink
show stats after user abort
Browse files Browse the repository at this point in the history
  • Loading branch information
wiggin77 committed Jun 8, 2022
1 parent 64d1857 commit d66017d
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,6 @@ func main() {
return
}

done := make(chan struct{})

setUpInterruptHandler(func() {
close(done)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
_ = lgr.ShutdownWithTimeout(ctx)
// give the workers a chance to shut down gracefully (some may not, that's ok).
time.Sleep(time.Second * 2)
})

admin, err := NewAdminClient(cfg)
if err != nil {
logger.Error("Cannot create admin client", logr.Err(err))
Expand All @@ -117,17 +106,34 @@ func main() {
return
}

done := make(chan struct{})
workersExited := make(chan struct{})

setUpInterruptHandler(func() {
close(done)

// give the workers a chance to shut down gracefully (some may not, that's ok).
select {
case <-workersExited:
case <-time.After(time.Second * 15):
}

// shutdown the logger
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
_ = lgr.ShutdownWithTimeout(ctx)
})

ri := &runInfo{
cfg: cfg,
logger: logger,
done: done,
admin: admin,
quiet: quiet,
}

start := time.Now()

run(ri)
run(ri, workersExited)

blockCount := atomic.LoadInt64(&ri.blockCount)
duration := time.Since(start)
Expand All @@ -139,7 +145,8 @@ func main() {
fmt.Printf("Blocks Per Second: %.2f\n", blocksPerSecond)
}

func run(ri *runInfo) {
func run(ri *runInfo, workersExited chan struct{}) {
defer close(workersExited)
var wg sync.WaitGroup
for i := 0; i < ri.cfg.UserCount; i++ {
wg.Add(1)
Expand Down Expand Up @@ -176,7 +183,7 @@ func setUpInterruptHandler(cleanUp func()) {
if cleanUp != nil {
cleanUp()
}
os.Exit(0)
os.Exit(1)
}()
}

Expand Down

0 comments on commit d66017d

Please sign in to comment.