Browse Source

assert results are sorted

pull/3739/head
chrislu 2 years ago
parent
commit
cc570a4477
  1. 15
      weed/util/limited_async_pool_test.go

15
weed/util/limited_async_pool_test.go

@ -2,6 +2,8 @@ package util
import ( import (
"fmt" "fmt"
"github.com/stretchr/testify/assert"
"sort"
"testing" "testing"
"time" "time"
) )
@ -16,43 +18,46 @@ func TestAsyncPool(t *testing.T) {
results = append(results, p.Execute(FourthFunc)) results = append(results, p.Execute(FourthFunc))
results = append(results, p.Execute(FifthFunc)) results = append(results, p.Execute(FifthFunc))
var sorted_results []int
for _, r := range results { for _, r := range results {
x := r.Await().(int) x := r.Await().(int)
println(x) println(x)
sorted_results = append(sorted_results, x)
} }
assert.True(t, sort.IntsAreSorted(sorted_results), "results should be sorted")
} }
func FirstFunc() any { func FirstFunc() any {
fmt.Println("-- Executing first function --") fmt.Println("-- Executing first function --")
time.Sleep(7 * time.Second)
time.Sleep(70 * time.Millisecond)
fmt.Println("-- First Function finished --") fmt.Println("-- First Function finished --")
return 1 return 1
} }
func SecondFunc() any { func SecondFunc() any {
fmt.Println("-- Executing second function --") fmt.Println("-- Executing second function --")
time.Sleep(5 * time.Second)
time.Sleep(50 * time.Millisecond)
fmt.Println("-- Second Function finished --") fmt.Println("-- Second Function finished --")
return 2 return 2
} }
func ThirdFunc() any { func ThirdFunc() any {
fmt.Println("-- Executing third function --") fmt.Println("-- Executing third function --")
time.Sleep(2 * time.Second)
time.Sleep(20 * time.Millisecond)
fmt.Println("-- Third Function finished --") fmt.Println("-- Third Function finished --")
return 3 return 3
} }
func FourthFunc() any { func FourthFunc() any {
fmt.Println("-- Executing fourth function --") fmt.Println("-- Executing fourth function --")
time.Sleep(10 * time.Second)
time.Sleep(100 * time.Millisecond)
fmt.Println("-- Fourth Function finished --") fmt.Println("-- Fourth Function finished --")
return 4 return 4
} }
func FifthFunc() any { func FifthFunc() any {
fmt.Println("-- Executing fifth function --") fmt.Println("-- Executing fifth function --")
time.Sleep(4 * time.Second)
time.Sleep(40 * time.Millisecond)
fmt.Println("-- Fourth fifth finished --") fmt.Println("-- Fourth fifth finished --")
return 5 return 5
} }
Loading…
Cancel
Save