Skip to content

Commit

Permalink
move test jobs into test file
Browse files Browse the repository at this point in the history
  • Loading branch information
samjjc committed Jan 23, 2018
1 parent 3308e4d commit b5bfdf0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Binary file added balance
Binary file not shown.
17 changes: 16 additions & 1 deletion balance_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package main

import "testing"
import (
"math/rand"
"testing"
"time"
)

func BenchmarkFastBalancer(b *testing.B) {
normalBalancer(b, fastJob)
Expand Down Expand Up @@ -53,3 +57,14 @@ func FiniteRequests(work chan<- Request, job func() int, size int) {
<-c
}
}

func constantJob() int {
time.Sleep(100 * time.Millisecond)
return 1
}

func fastJob() int {
y := rand.Intn(1000)
x := 2 * y
return x
}
13 changes: 1 addition & 12 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,8 @@ func InfiniteRequester(work chan<- Request, job func() int) {
func randomFailingJob() int {
randDuration := time.Duration(rand.Intn(4000)) * time.Millisecond
time.Sleep(randDuration)
if randDuration <= time.Millisecond*400 {
if randDuration <= time.Millisecond*400 { //random failure
panic("3 FAST 5 ME")
}
return 1
}

func constantJob() int {
time.Sleep(100 * time.Millisecond)
return 1
}

func fastJob() int {
y := rand.Intn(1000)
x := 2 * y
return x
}

0 comments on commit b5bfdf0

Please sign in to comment.