Created
January 26, 2018 19:40
-
-
Save cep21/8db817c56bbb2d1163287708e6c1aeae to your computer and use it in GitHub Desktop.
Example integration test
This file contains hidden or 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 trace_110 | |
import ( | |
"testing" | |
"sync" | |
"fmt" | |
"time" | |
"net/http" | |
) | |
func takeCPU(start time.Time, wg *sync.WaitGroup) { | |
defer wg.Done() | |
j := 3 | |
for time.Since(start) < time.Second { | |
for i :=1; i < 1000000; i++ { | |
j *= i | |
} | |
} | |
fmt.Println(j) | |
} | |
func takeTimeOnly(wg *sync.WaitGroup) { | |
defer wg.Done() | |
time.Sleep(time.Second * 3) | |
} | |
func takeIO(start time.Time, wg *sync.WaitGroup) { | |
defer wg.Done() | |
errCount := 0 | |
for time.Since(start) < time.Second * 4{ | |
_, err := http.Get("https://www.google.com") | |
if err != nil { | |
errCount++ | |
} | |
} | |
fmt.Println(errCount) | |
} | |
func startServer() { | |
wg := sync.WaitGroup{} | |
wg.Add(3) | |
start := time.Now() | |
go takeCPU(start, &wg) | |
go takeTimeOnly(&wg) | |
go takeIO(start, &wg) | |
wg.Wait() | |
} | |
func TestServer(t *testing.T) { | |
startServer() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment