-
Notifications
You must be signed in to change notification settings - Fork 69
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
1dc3a95
commit d5bead8
Showing
11 changed files
with
131 additions
and
71 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2021 Wayback Archiver. All rights reserved. | ||
// Use of this source code is governed by the GNU GPL v3 | ||
// license that can be found in the LICENSE file. | ||
|
||
package pooling // import "github.com/wabarc/wayback/pooling" | ||
|
||
import ( | ||
"runtime" | ||
"sync" | ||
"sync/atomic" | ||
"testing" | ||
"time" | ||
|
||
"github.com/wabarc/logger" | ||
) | ||
|
||
func TestTimeout(t *testing.T) { | ||
logger.SetLogLevel(logger.LevelFatal) | ||
|
||
maxTime = time.Microsecond | ||
|
||
c := 2 | ||
p := New(c) | ||
|
||
var i int32 | ||
var wg sync.WaitGroup | ||
for i < 5 { | ||
wg.Add(1) | ||
p.Roll(func() { | ||
time.Sleep(time.Millisecond) | ||
}) | ||
wg.Done() | ||
atomic.AddInt32(&i, 1) | ||
runtime.Gosched() | ||
} | ||
wg.Wait() | ||
|
||
if len(p) != c { | ||
t.Fatalf("The length of pool got %d instead of %d", len(p), c) | ||
} | ||
|
||
p.Roll(func() { | ||
time.Sleep(time.Millisecond) | ||
}) | ||
|
||
if len(p) != c { | ||
t.Fatalf("The length of pool got %d instead of %d", len(p), c) | ||
} | ||
} |
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
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
Oops, something went wrong.