This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DoAll: Better panic handling; reorganize tests
- Loading branch information
1 parent
daa7c70
commit 04600bb
Showing
4 changed files
with
88 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package workgroup_test | ||
|
||
import "testing" | ||
|
||
func TestDoAll_err(t *testing.T) { | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package workgroup_test | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
"time" | ||
|
||
"github.com/carlmjohnson/workgroup" | ||
) | ||
|
||
func TestDoTasks_drainage(t *testing.T) { | ||
const sleepTime = 10 * time.Millisecond | ||
b := false | ||
task := func(n int) (int, error) { | ||
if n == 1 { | ||
return 0, errors.New("text string") | ||
} | ||
time.Sleep(sleepTime) | ||
b = true | ||
return 0, nil | ||
} | ||
start := time.Now() | ||
m := map[int]struct { | ||
int | ||
error | ||
}{} | ||
manager := func(in, out int, err error) ([]int, bool) { | ||
m[in] = struct { | ||
int | ||
error | ||
}{out, err} | ||
if err != nil { | ||
return nil, false | ||
} | ||
return nil, true | ||
} | ||
workgroup.DoTasks(5, task, manager, 0, 1) | ||
if s := fmt.Sprint(m); s != "map[1:text string]" { | ||
t.Fatal(s) | ||
} | ||
if time.Since(start) < sleepTime { | ||
t.Fatal("didn't sleep enough") | ||
} | ||
if !b { | ||
t.Fatal("didn't finish") | ||
} | ||
} |
This file contains 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