Last active
May 11, 2018 13:21
-
-
Save itarato/30e2eeda56156e4c2ce7f002171326fb to your computer and use it in GitHub Desktop.
Stress test of discount code creation
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
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