-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix semaphore in parallel polling monitor (#4927)
Signed-off-by: Ben Sherman <[email protected]> Signed-off-by: Paolo Di Tommaso <[email protected]> Co-authored-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
a28b404
commit d173cea
Showing
2 changed files
with
47 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -16,13 +16,15 @@ | |
|
||
package nextflow.processor | ||
|
||
|
||
import java.util.concurrent.TimeUnit | ||
import java.util.concurrent.atomic.AtomicInteger | ||
|
||
import nextflow.Session | ||
import nextflow.util.Duration | ||
import nextflow.util.ThrottlingExecutor | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
|
@@ -71,4 +73,48 @@ class ParallelPollingMonitorTest extends Specification { | |
|
||
} | ||
|
||
@Unroll | ||
def 'should validate can submit method' () { | ||
given: | ||
def success = new AtomicInteger() | ||
def failure = new AtomicInteger() | ||
def count = new AtomicInteger() | ||
def change = new AtomicInteger() | ||
def retry = new AtomicInteger() | ||
|
||
def session = Mock(Session) | ||
def handler = Mock(TaskHandler) | ||
|
||
def opts = new ThrottlingExecutor.Options() | ||
.retryOn(IllegalArgumentException) | ||
.withRateLimit('10/sec') | ||
.withErrorBurstDelay(Duration.of('5sec')) | ||
.withAutoThrottle() | ||
.onSuccess { success.incrementAndGet() } | ||
.onRetry { retry.incrementAndGet() } | ||
.onFailure { failure.incrementAndGet() } | ||
.onRateLimitChange { change.incrementAndGet() } | ||
|
||
def exec = ThrottlingExecutor.create(opts) | ||
def mon = Spy(new ParallelPollingMonitor(exec, [capacity:CAPACITY, session:session, name:'foo', pollInterval:'1sec'])) | ||
and: | ||
SUBMIT.times { mon.runningQueue.add(Mock(TaskHandler)) } | ||
|
||
when: | ||
def result = mon.canSubmit(handler) | ||
then: | ||
handler.canForkProcess() >> FORK | ||
and: | ||
result == EXPECTED | ||
|
||
where: | ||
CAPACITY | SUBMIT | FORK | EXPECTED | ||
0 | 5 | true | true | ||
10 | 5 | true | true | ||
10 | 10 | true | false | ||
and: | ||
0 | 1 | false | false | ||
10 | 1 | false | false | ||
} | ||
|
||
} |