-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_delete_test.go
49 lines (38 loc) · 918 Bytes
/
api_delete_test.go
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
43
44
45
46
47
48
49
package main
import (
"fmt"
"net/http"
"sync"
"testing"
)
func TestConcurrentDeleteRequests(t *testing.T) {
const numRequests = 200
const baseURL = "http://localhost:8080/api/"
var wg sync.WaitGroup
client := &http.Client{} // Create an HTTP client
for i := 1; i <= numRequests; i++ {
wg.Add(1)
go func(key string) {
defer wg.Done()
// Create a DELETE request
req, err := http.NewRequest("DELETE", baseURL + key, nil)
if err != nil {
t.Errorf("DELETE request failed: %v", err)
return
}
// Send DELETE request
resp, err := client.Do(req)
if err != nil {
t.Errorf("DELETE 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)
}
}(fmt.Sprintf("key%d", i))
}
// Wait for all requests to finish
wg.Wait()
}