View | Details | Raw Unified | Return to bug 62637
Collapse All | Expand All

(-)a/src/components/org/apache/jmeter/timers/SyncTimer.java (-5 / +8 lines)
Lines 171-184 public class SyncTimer extends AbstractTestElement implements Timer, Serializabl Link Here
171
        if(getGroupSize()>=0) {
171
        if(getGroupSize()>=0) {
172
            int arrival = 0;
172
            int arrival = 0;
173
            try {
173
            try {
174
                if(timeoutInMs==0) {
174
                if (timeoutInMs <= 0) {
175
                    arrival = this.barrier.await();                    
175
                    arrival = this.barrier.await(TimerService.getInstance().adjustDelay(Long.MAX_VALUE), TimeUnit.MILLISECONDS);
176
                } else if(timeoutInMs > 0){
176
                } else if(timeoutInMs > 0) {
177
                    arrival = this.barrier.await(timeoutInMs, TimeUnit.MILLISECONDS);
177
                    arrival = this.barrier.await(TimerService.getInstance().adjustDelay(timeoutInMs), TimeUnit.MILLISECONDS);
178
                } else {
178
                } else {
179
                    throw new IllegalArgumentException("Negative value for timeout:"+timeoutInMs+" in Synchronizing Timer "+getName());
179
                    throw new IllegalArgumentException("Negative value for timeout:"+timeoutInMs+" in Synchronizing Timer "+getName());
180
                }
180
                }
181
            } catch (InterruptedException | BrokenBarrierException e) {
181
            } catch (InterruptedException e) {
182
                Thread.currentThread().interrupt();
183
                return 0;
184
            } catch (BrokenBarrierException e) {
182
                return 0;
185
                return 0;
183
            } catch (TimeoutException e) {
186
            } catch (TimeoutException e) {
184
                if (log.isWarnEnabled()) {
187
                if (log.isWarnEnabled()) {
(-)a/test/src/org/apache/jmeter/timers/SyncTimerSpec.groovy (-1 / +95 lines)
Line 0 Link Here
0
- 
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *   http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 */
18
19
package org.apache.jmeter.timers
20
21
import org.apache.jmeter.threads.JMeterContext
22
import org.apache.jmeter.threads.JMeterContextService
23
import org.apache.jmeter.threads.JMeterThread
24
25
import spock.lang.Specification
26
27
class SyncTimerSpec extends Specification {
28
    
29
    
30
    def "timer with scheduled end point"() {
31
        setup:
32
            def timer = new SyncTimer()
33
            def ctx = Stub(JMeterContext)
34
            def thread = Stub(JMeterThread)
35
36
            thread.getEndTime() >> System.currentTimeMillis() + 100L
37
            ctx.getThread() >> thread
38
39
            timer.threadContext = ctx
40
            timer.groupSize = 2
41
            timer.testStarted()
42
         when:
43
            def start = System.currentTimeMillis();
44
            def delay = timer.delay()
45
            def elapsed = System.currentTimeMillis() - start
46
         then:
47
            delay == 0
48
            elapsed < 10 * 100L
49
    }
50
51
    def "timer with scheduled end point and shorter max timeout in ms"() {
52
        setup:
53
            def timer = new SyncTimer()
54
            timer.setTimeoutInMs(100L)
55
            def ctx = Stub(JMeterContext)
56
            def thread = Stub(JMeterThread)
57
58
            thread.getEndTime() >> System.currentTimeMillis() + 2000L
59
            ctx.getThread() >> thread
60
61
            timer.threadContext = ctx
62
            timer.groupSize = 2
63
            timer.testStarted()
64
         when:
65
            def start = System.currentTimeMillis();
66
            def delay = timer.delay()
67
            def elapsed = System.currentTimeMillis() - start
68
         then:
69
            delay == 0
70
            elapsed < 10 * 100L
71
    }
72
73
    def "timer with scheduled end point and longer max timeout in ms"() {
74
        setup:
75
            def timer = new SyncTimer()
76
            timer.setTimeoutInMs(2000L)
77
            def ctx = Stub(JMeterContext)
78
            def thread = Stub(JMeterThread)
79
80
            thread.getEndTime() >> System.currentTimeMillis() + 100L
81
            ctx.getThread() >> thread
82
83
            timer.threadContext = ctx
84
            timer.groupSize = 2
85
            timer.testStarted()
86
         when:
87
            def start = System.currentTimeMillis();
88
            def delay = timer.delay()
89
            def elapsed = System.currentTimeMillis() - start
90
         then:
91
            delay == 0
92
            elapsed < 10 * 100L
93
    }
94
95
}

Return to bug 62637