-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea82867
commit a9b0a02
Showing
4 changed files
with
80 additions
and
25 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
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 |
---|---|---|
@@ -1 +1,41 @@ | ||
package cartel | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
) | ||
|
||
func Test_Runs_One_Per_Second(t *testing.T) { | ||
|
||
p := NewPool( | ||
PoolOptions{ | ||
Size: 1, | ||
PerDuration: 1, | ||
Duration: time.Second, | ||
}, | ||
) | ||
p.Do(TestTimeTask{}) | ||
p.Do(TestTimeTask{}) | ||
p.End() | ||
|
||
values := p.GetOutput() | ||
|
||
if actual := len(values); actual != 2 { | ||
t.Errorf("expected 2 items but got %v", actual) | ||
} | ||
|
||
firstTime := values[0].(time.Time) | ||
secondTime := values[1].(time.Time) | ||
|
||
d := secondTime.Sub(firstTime) | ||
if d.Seconds() < 1 { | ||
t.Errorf("expected 1 seconds but got %v - %v %v", d.Seconds(), firstTime, secondTime) | ||
} | ||
} | ||
|
||
type TestTimeTask struct { | ||
} | ||
|
||
func (ttt TestTimeTask) Execute() interface{} { | ||
return time.Now() | ||
} |