mirror of
https://github.com/NotAShelf/tct.git
synced 2025-10-02 15:03:48 +00:00
unit tests
This commit is contained in:
parent
4809f916cd
commit
a0955a4f6b
4 changed files with 95 additions and 3 deletions
15
main.go
15
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
|
@ -12,6 +13,12 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type HttpClient interface {
|
||||
Get(url string) (*http.Response, error)
|
||||
}
|
||||
|
||||
var httpClient HttpClient = &http.Client{}
|
||||
|
||||
func main() {
|
||||
urlPtr := flag.String("url", "http://example.com", "URL to fetch")
|
||||
maxRequestsPtr := flag.Int("max", 100, "Maximum number of parallel requests")
|
||||
|
@ -45,7 +52,7 @@ func main() {
|
|||
return
|
||||
default:
|
||||
time.Sleep(delay)
|
||||
makeRequest(url)
|
||||
makeRequest(httpClient, url)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
@ -60,11 +67,13 @@ func main() {
|
|||
fmt.Printf("\nOptimal Number of Parallel TCP Requests: %d\n", optimal)
|
||||
}
|
||||
|
||||
func makeRequest(url string) {
|
||||
resp, err := http.Get(url)
|
||||
func makeRequest(client HttpClient, url string) {
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
_ = body
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue