-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_get_test.go
More file actions
42 lines (34 loc) · 817 Bytes
/
api_get_test.go
File metadata and controls
42 lines (34 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"net/http"
"sync"
"testing"
)
func TestConcurrentGetRequests(t *testing.T) {
const numRequests = 200
const baseURL = "http://localhost:8080/api/" // Replace with your API base URL
var wg sync.WaitGroup
// Send concurrent GET requests
for i := 1; i <= numRequests; i++ {
wg.Add(1)
go func(key string) {
defer wg.Done()
// Send GET request to the server
resp, err := http.Get(baseURL + key)
if err != nil {
t.Errorf("GET request failed: %v", err)
return
}
defer resp.Body.Close()
// Check response status code
if resp.StatusCode != http.StatusOK {
t.Errorf("Unexpected status code: %d", resp.StatusCode)
return
}
// Process response if needed
}(fmt.Sprintf("key%d", i))
}
// Wait for all requests to finish
wg.Wait()
}