Skip to content

Instantly share code, notes, and snippets.

@cep21
Created January 26, 2018 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cep21/8db817c56bbb2d1163287708e6c1aeae to your computer and use it in GitHub Desktop.
Save cep21/8db817c56bbb2d1163287708e6c1aeae to your computer and use it in GitHub Desktop.
Example integration test
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