Skip to content

Commit

Permalink
linting: gosimple fixes (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
bengadbois authored Jan 19, 2021
1 parent 57c99d7 commit 08c9e19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 32 deletions.
11 changes: 5 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ func init() {
viper.SetConfigName("pewpew") // name of config file (without extension)
viper.AddConfigPath(".") // optionally look for config in the working directory
err := viper.ReadInConfig() // Find and read the config file
if err != nil { // Handle errors reading the config file
if _, ok := err.(viper.ConfigParseError); ok {
fmt.Println("Failed to parse config file " + viper.ConfigFileUsed())
fmt.Println(err)
os.Exit(-1)
}
// Handle errors reading the config file
if _, ok := err.(viper.ConfigParseError); ok {
fmt.Println("Failed to parse config file " + viper.ConfigFileUsed())
fmt.Println(err)
os.Exit(-1)
}

if viper.ConfigFileUsed() != "" {
Expand Down
48 changes: 22 additions & 26 deletions lib/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,40 +104,36 @@ func RunBenchmark(b BenchmarkConfig, w io.Writer) ([][]RequestStat, error) {
secondsLeft := b.Duration
go func() {
for {
select {
case <-ticker.C:
secondsLeft--
if secondsLeft < 0 {
return
}
for i := 0; i < b.RPS; i++ {
//run all the requests at the start of the second
//note: this means it's a little bursty, not evenly
//distributed throughout the 1 second window
go func() {
req := <-requestQueue
response, stat := runRequest(req, client)
if !b.Quiet {
p.printStat(stat)
if b.Verbose {
p.printVerbose(&req, response)
}
<-ticker.C
secondsLeft--
if secondsLeft < 0 {
return
}
for i := 0; i < b.RPS; i++ {
//run all the requests at the start of the second
//note: this means it's a little bursty, not evenly
//distributed throughout the 1 second window
go func() {
req := <-requestQueue
response, stat := runRequest(req, client)
if !b.Quiet {
p.printStat(stat)
if b.Verbose {
p.printVerbose(&req, response)
}
requestStatChan <- stat
}()
}
}
requestStatChan <- stat
}()
}
}
}()

requestStats := make([]RequestStat, b.RPS*b.Duration)
requestsCompleteCount := 0
for {
select {
case stat := <-requestStatChan:
requestStats[requestsCompleteCount] = stat
requestsCompleteCount++
}
stat := <-requestStatChan
requestStats[requestsCompleteCount] = stat
requestsCompleteCount++
if requestsCompleteCount == b.RPS*b.Duration {
//all requests are finished
break
Expand Down

0 comments on commit 08c9e19

Please sign in to comment.