Skip to content

Instantly share code, notes, and snippets.

@itarato
Last active May 11, 2018 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itarato/30e2eeda56156e4c2ce7f002171326fb to your computer and use it in GitHub Desktop.
Save itarato/30e2eeda56156e4c2ce7f002171326fb to your computer and use it in GitHub Desktop.
Stress test of discount code creation
package main
import "gopkg.in/resty.v1"
import "fmt"
import "log"
import "strconv"
import "sync"
func main() {
var wg sync.WaitGroup
for j := 0; j < 100; j++ {
for i := 0; i < 3; i++ {
wg.Add(1)
go func(uid int) {
defer wg.Done()
resp, err := resty.R().
SetHeaders(map[string]string{
"Content-Type": "application/json",
"Accept": "application/json",
}).
SetBody(`{"discount_code": {"code": "CODE_` + strconv.Itoa(uid) + `"}}`).
Post("https://<API_KEY>:<API_SECRET>@<DOMAIN>/admin/price_rules/<PRICE_RULE_ID>/discount_codes.json")
if err != nil {
log.Fatalf("Error: %v", err)
}
fmt.Printf("\nResponse Status Code: %v", resp.StatusCode())
fmt.Printf("\nResponse Body: %s", resp.String())
}(j)
}
}
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment