Create a gist now

Instantly share code, notes, and snippets.

Embed
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