Created
January 12, 2024 17:18
-
-
Save ethanquix/b42a96a527a15c7fb73dff83da4addf5 to your computer and use it in GitHub Desktop.
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 ( | |
"context" | |
"fmt" | |
"log" | |
"net/http" | |
"sync" | |
"testing" | |
"time" | |
"golang.org/x/net/context/ctxhttp" | |
) | |
func doReq(wg *sync.WaitGroup) { | |
defer wg.Done() | |
ctx, _ := context.WithTimeout(context.Background(), time.Millisecond*1000) | |
//defer cancel() | |
req, err := http.NewRequest("GET", "https://jsonplaceholder.typicode.com/posts", nil) | |
if err != nil { | |
log.Fatal(err) | |
} | |
//req = req.WithContext(ctx) | |
_, err = ctxhttp.Do(ctx, http.DefaultClient, req) | |
} | |
func TestABC(t *testing.T) { | |
now := time.Now() | |
wg := &sync.WaitGroup{} | |
for i := 0; i < 400; i++ { | |
wg.Add(1) | |
go doReq(wg) | |
} | |
wg.Wait() | |
fmt.Printf("took %d ms\n", time.Since(now).Milliseconds()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment