How to use DeterministicSchedulerTests class of org.jmock.test.unit.lib.concurrent package

Best Jmock-library code snippet using org.jmock.test.unit.lib.concurrent.DeterministicSchedulerTests

Run Jmock-library automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

copy
1package org.jmock.test.unit.lib.concurrent;
2
3
4import static org.hamcrest.Matchers.equalTo;
5import static org.hamcrest.Matchers.sameInstance;
6import static org.junit.Assert.assertThat;
7
8import java.util.concurrent.Callable;
9import java.util.concurrent.ExecutionException;
10import java.util.concurrent.Future;
11import java.util.concurrent.ScheduledFuture;
12import java.util.concurrent.TimeUnit;
13
14import org.jmock.Expectations;
15import org.jmock.Sequence;
16import org.jmock.api.Action;
17import org.jmock.integration.junit3.MockObjectTestCase;
18import org.jmock.lib.concurrent.DeterministicScheduler;
19import org.jmock.lib.concurrent.UnsupportedSynchronousOperationException;
20
21public class DeterministicSchedulerTests extends MockObjectTestCase {
22    DeterministicScheduler scheduler = new DeterministicScheduler();
23    
24    Runnable commandA = mock(Runnable.class, "commandA");
25    Runnable commandB = mock(Runnable.class, "commandB");
26    Runnable commandC = mock(Runnable.class, "commandC");
27    Runnable commandD = mock(Runnable.class, "commandD");
28    
29    @SuppressWarnings("unchecked")
30    Callable<String> callableA = mock(Callable.class, "callableA");
31    
32    public void testRunsPendingCommandsUntilIdle() {
33        scheduler.execute(commandA);
34        scheduler.execute(commandB);
35        
36        final Sequence executionOrder = sequence("executionOrder");
37        
38        checking(new Expectations() {{
39            oneOf (commandA).run(); inSequence(executionOrder);
40            oneOf (commandB).run(); inSequence(executionOrder);
41        }});
42        
43        assertFalse(scheduler.isIdle());
44        
45        scheduler.runUntilIdle();
46        
47        assertTrue(scheduler.isIdle());
48    }
49    
50    public void testCanRunCommandsSpawnedByExecutedCommandsUntilIdle() {
51        scheduler.execute(commandA);
52        scheduler.execute(commandB);
53        
54        final Sequence executionOrder = sequence("executionOrder");
55        
56        checking(new Expectations() {{
57            oneOf (commandA).run(); inSequence(executionOrder); will(schedule(commandC));
58            oneOf (commandB).run(); inSequence(executionOrder); will(schedule(commandD));
59            oneOf (commandC).run(); inSequence(executionOrder);
60            oneOf (commandD).run(); inSequence(executionOrder);
61        }});
62        
63        scheduler.runUntilIdle();
64    }
65    
66    public void testCanScheduleCommandAndReturnFuture() throws InterruptedException, ExecutionException {
67        Future<?> future = scheduler.submit(commandA);
68        
69        checking(new Expectations() {{
70            oneOf (commandA).run();
71        }});
72        
73        assertTrue("future should not be done before running the task", !future.isDone());
74        
75        scheduler.runUntilIdle();
76        
77        assertTrue("future should be done after running the task", future.isDone());
78        assertNull("result of future should be null", future.get());
79    }
80    
81    public void testCanScheduleCommandAndResultAndReturnFuture() throws InterruptedException, ExecutionException {
82        Future<String> future = scheduler.submit(commandA, "result1");
83        
84        checking(new Expectations() {{
85            oneOf (commandA).run();
86        }});
87       
88        scheduler.runUntilIdle();
89        
90        assertThat(future.get(), equalTo("result1"));
91    }
92
93    public void testCanScheduleCallableAndReturnFuture() throws Exception {
94        Future<String> future = scheduler.submit(callableA);
95        
96        checking(new Expectations() {{
97            oneOf (callableA).call(); will(returnValue("result2"));
98        }});
99        
100        scheduler.runUntilIdle();
101        
102        assertThat(future.get(), equalTo("result2"));
103    }
104
105    public void testScheduledCallablesCanReturnNull() throws Exception {
106        checking(new Expectations() {{
107            oneOf (callableA).call(); will(returnValue(null));
108        }});
109        
110        Future<String> future = scheduler.submit(callableA);
111        
112        scheduler.runUntilIdle();
113        
114        assertNull(future.get());
115    }
116    
117    public class ExampleException extends Exception {}
118    
119    public void testExceptionThrownByScheduledCallablesIsThrownFromFuture() throws Exception {
120        final Throwable thrown = new ExampleException();
121        
122        checking(new Expectations() {{
123            oneOf (callableA).call(); will(throwException(thrown));
124        }});
125        
126        Future<String> future = scheduler.submit(callableA);
127        
128        scheduler.runUntilIdle();
129        
130        try {
131            future.get();
132            fail("should have thrown ExecutionException");
133        }
134        catch (ExecutionException expected) {
135            assertThat(expected.getCause(), sameInstance(thrown));
136        }
137    }
138
139    public void testCanScheduleCommandsToBeExecutedAfterADelay() {
140        scheduler.schedule(commandA, 10, TimeUnit.SECONDS);
141        
142        scheduler.tick(9, TimeUnit.SECONDS);
143        
144        checking(new Expectations() {{
145            oneOf (commandA).run();
146        }});
147        
148        scheduler.tick(1, TimeUnit.SECONDS);
149    }
150    
151    public void testTickingTimeForwardRunsAllCommandsScheduledDuringThatTimePeriod() {
152        scheduler.schedule(commandA, 1, TimeUnit.MILLISECONDS);
153        scheduler.schedule(commandB, 2, TimeUnit.MILLISECONDS);
154        
155        checking(new Expectations() {{
156            oneOf (commandA).run();
157            oneOf (commandB).run();
158        }});
159        
160        scheduler.tick(3, TimeUnit.MILLISECONDS);
161    }
162    
163    public void testTickingTimeForwardRunsCommandsExecutedByScheduledCommands() {
164        scheduler.schedule(commandA, 1, TimeUnit.MILLISECONDS);
165        scheduler.schedule(commandD, 2, TimeUnit.MILLISECONDS);
166        
167        checking(new Expectations() {{
168            oneOf (commandA).run(); will(schedule(commandB));
169            oneOf (commandB).run(); will(schedule(commandC));
170            oneOf (commandC).run();
171            oneOf (commandD).run();
172        }});
173        
174        scheduler.tick(3, TimeUnit.MILLISECONDS);
175    }
176    
177    public void testCanExecuteCommandsThatRepeatWithFixedDelay() {
178        scheduler.scheduleWithFixedDelay(commandA, 2L, 3L, TimeUnit.SECONDS);
179        
180        checking(new Expectations() {{
181            exactly(3).of(commandA).run();
182        }});
183        
184        scheduler.tick(8L, TimeUnit.SECONDS);
185    }
186
187    public void testCanExecuteCommandsThatRepeatAtFixedRateButAssumesThatCommandsTakeNoTimeToExecute() {
188        scheduler.scheduleAtFixedRate(commandA, 2L, 3L, TimeUnit.SECONDS);
189        
190        checking(new Expectations() {{
191            exactly(3).of(commandA).run();
192        }});
193        
194        scheduler.tick(8L, TimeUnit.SECONDS);
195    }
196    
197    public void testCanCancelScheduledCommands() {
198        final boolean dontCare = true;
199        ScheduledFuture<?> future = scheduler.schedule(commandA, 1, TimeUnit.SECONDS);
200        
201        assertFalse(future.isCancelled());
202        future.cancel(dontCare);
203        assertTrue(future.isCancelled());
204        
205        checking(new Expectations() {{
206            never (commandA);
207        }});
208        
209        scheduler.tick(2, TimeUnit.SECONDS);
210    }
211    
212    static final int TIMEOUT_IGNORED = 1000;
213    
214    public void testCanScheduleCallablesAndGetTheirResultAfterTheyHaveBeenExecuted() throws Exception {
215        checking(new Expectations() {{
216            oneOf (callableA).call(); will(returnValue("A"));
217        }});
218        
219        ScheduledFuture<String> future = scheduler.schedule(callableA, 1, TimeUnit.SECONDS);
220        
221        assertTrue("is not done", !future.isDone());
222        
223        scheduler.tick(1, TimeUnit.SECONDS);
224        
225        assertTrue("is done", future.isDone());
226        assertThat(future.get(), equalTo("A"));
227        assertThat(future.get(TIMEOUT_IGNORED, TimeUnit.SECONDS), equalTo("A"));
228    }
229
230    public void testCannotBlockWaitingForFutureResultOfScheduledCallable() throws Exception {
231        ScheduledFuture<String> future = scheduler.schedule(callableA, 1, TimeUnit.SECONDS);
232        
233        try {
234            future.get();
235            fail("should have thrown UnsupportedSynchronousOperationException");
236        }
237        catch (UnsupportedSynchronousOperationException expected) {}
238        
239        try {
240            future.get(TIMEOUT_IGNORED, TimeUnit.SECONDS);
241            fail("should have thrown UnsupportedSynchronousOperationException");
242        }
243        catch (UnsupportedSynchronousOperationException expected) {}
244    }
245    
246    private Action schedule(final Runnable command) {
247        return ScheduleOnExecutorAction.schedule(scheduler, command);
248    }
249}
250
Full Screen
copy
1package com.github.foeser.teamcity.elastictimeout;
2
3import ch.qos.logback.classic.Level;
4import ch.qos.logback.classic.Logger;
5import ch.qos.logback.classic.LoggerContext;
6import com.github.foeser.teamcity.elastictimeout.schedulers.ManualScheduler;
7import com.github.foeser.teamcity.elastictimeout.utils.MemoryAppender;
8import jetbrains.buildServer.BuildProblemData;
9import jetbrains.buildServer.web.openapi.PluginDescriptor;
10import org.slf4j.LoggerFactory;
11
12import jetbrains.buildServer.BaseTestCase;
13import jetbrains.buildServer.serverSide.*;
14import jetbrains.buildServer.util.EventDispatcher;
15
16import org.jmock.Mockery;
17import org.jmock.Expectations;
18import org.testng.annotations.BeforeMethod;
19import org.testng.annotations.Test;
20
21import java.util.*;
22
23import static com.github.foeser.teamcity.elastictimeout.ElasticTimeoutFailureCondition.*;
24
25// https://github.com/jmock-developers/jmock-library/blob/master/jmock/src/test/java/org/jmock/test/unit/lib/concurrent/DeterministicSchedulerTests.java#L177
26
27public class ElasticTimeOutPluginTests extends BaseTestCase {
28    private Mockery context;
29    private BuildEventListener buildEventListener;
30    private BuildTimeoutHandler buildTimeoutHandler;
31    private SBuildFeatureDescriptor mockSBuildFeatureDescriptor;
32    private BuildHistory buildHistory;
33    private MemoryAppender memoryAppender;
34    private MemoryAppender memoryAppenderBuildTimeoutHandler;
35    private ManualScheduler manualScheduler;
36    private RunningBuildsManager runningBuildsManager;
37    private ElasticTimeoutFailureCondition failureCondition;
38
39    @BeforeMethod
40    @Override
41    public void setUp() throws Exception {
42        super.setUp();
43        context = new Mockery();
44        final EventDispatcher<BuildServerListener> eventDispatcher = EventDispatcher.create(BuildServerListener.class);
45        runningBuildsManager = context.mock(RunningBuildsManager.class);
46        buildHistory = context.mock(BuildHistory.class);
47        mockSBuildFeatureDescriptor = context.mock(SBuildFeatureDescriptor.class);
48
49        manualScheduler = new ManualScheduler();
50        buildTimeoutHandler = new BuildTimeoutHandler(manualScheduler, runningBuildsManager, buildHistory);
51        buildEventListener = new BuildEventListener(eventDispatcher, buildTimeoutHandler);
52
53        PluginDescriptor mockPluginDescriptor = context.mock(PluginDescriptor.class);
54        context.checking(new Expectations() {
55            {
56                oneOf(mockPluginDescriptor).getPluginResourcesPath("ElasticTimeoutFailureConditionSettings.jsp"); will (returnValue(""));
57            }
58        });
59        failureCondition = new ElasticTimeoutFailureCondition(mockPluginDescriptor);
60
61        // Todo: Test if actually logging on Teamcity works (maybe switch to AppenderSkeleton then: https://stackoverflow.com/a/1828268/1072693)
62        // Todo: no it doesn't with slf4j :(
63        // in order to just get simple logs printed to console we can set the log Level to DEBUG (as the root level set in log4j.xml get set later back to WARN, see debug output)
64        // also logback (at least context) would need to be removed and assuming using org.apache.log4j and not org.slf4j
65        //org.apache.log4j.Logger.getLogger(BuildEventListener.class).setLevel(org.apache.log4j.Level.DEBUG);
66
67        memoryAppender = new MemoryAppender();
68        memoryAppender.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
69        memoryAppenderBuildTimeoutHandler = new MemoryAppender();
70        memoryAppenderBuildTimeoutHandler.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
71        Logger loggerBuildEventListener = (Logger) LoggerFactory.getLogger(BuildEventListener.class);
72        loggerBuildEventListener.setLevel(Level.DEBUG);
73        loggerBuildEventListener.addAppender(memoryAppender);
74        Logger loggerBuildTimeoutHandler = (Logger) LoggerFactory.getLogger(BuildTimeoutHandler.class);
75        loggerBuildTimeoutHandler.setLevel(Level.DEBUG);
76        loggerBuildTimeoutHandler.addAppender(memoryAppenderBuildTimeoutHandler);
77        memoryAppender.start();
78        memoryAppenderBuildTimeoutHandler.start();
79    }
80
81    @Test
82    // add build (configuration) without ElasticTimeout build feature enabled, expected result would be that it won't get considered at all
83    public void addBuildWithoutBuildFeature() {
84        final SRunningBuild mockSRunningBuild = context.mock(SRunningBuild.class);
85        context.checking(new Expectations() {
86           {
87               // let's simply return an empty array
88               oneOf(mockSRunningBuild).getBuildFeaturesOfType(ElasticTimeoutFailureCondition.TYPE); will (returnValue( new ArrayList<SBuildFeatureDescriptor>()));
89           }
90        });
91        buildEventListener.buildStarted(mockSRunningBuild);
92        assertEquals(0, buildTimeoutHandler.getCurrentBuildsInConsideration());
93        assertEquals(1, memoryAppender.search(String.format("%s doesn't have the elastic timeout failure condition set or enabled. Skipping...", mockSRunningBuild)).size());
94    }
95    @Test
96    // add valid build (timeout feature enabled with proper build history) but finish it earlier, expected result would be that it get removed from consideration
97    public void removeBuild() {
98        final SRunningBuild mockSRunningBuild = context.mock(SRunningBuild.class);
99        final Map<String, String> elasticTimeoutFailureConditionParameters = failureCondition.getDefaultParameters();
100        final SFinishedBuild mockSFinishedBuild = context.mock(SFinishedBuild.class);
101
102        context.checking(new Expectations() {
103            {
104                // get called twice, once while adding (buildStarted) and once while removing (beforeBuildFinish)
105                atLeast(2).of(mockSRunningBuild).getBuildFeaturesOfType(ElasticTimeoutFailureCondition.TYPE); will (returnValue(Collections.singleton(mockSBuildFeatureDescriptor)));
106                oneOf(mockSBuildFeatureDescriptor).getParameters(); will (returnValue(elasticTimeoutFailureConditionParameters));
107                // based on plugins default settings we add three builds to the history and querying accordingly three times the duration (returning different values each time)
108                oneOf(buildHistory).getEntriesBefore(mockSRunningBuild, true); will (returnValue(Arrays.asList(mockSFinishedBuild, mockSFinishedBuild, mockSFinishedBuild)));
109                atLeast(3).of (mockSFinishedBuild).getDuration();
110                will(onConsecutiveCalls(
111                        returnValue(10L),
112                        returnValue(20L),
113                        returnValue(30L)));
114                // get called twice, within scheduler and once while removing
115                atLeast(2).of(mockSRunningBuild).getBuildId(); will (returnValue(1L));
116                // get invoked twice within scheduler, and return below timeout value (45s)
117                atLeast(2).of(runningBuildsManager).findRunningBuildById(1L); will (returnValue(mockSRunningBuild));
118                atLeast(2).of(mockSRunningBuild).getDuration();
119                will(onConsecutiveCalls(
120                        returnValue(13L),
121                        returnValue(38L)));
122                // not working :( while actually using oneOf() would work, no clue...
123                //never(mockSRunningBuild).stop(with(any(DummyUser.class)), with(any(String.class)));
124            }
125        });
126        buildEventListener.buildStarted(mockSRunningBuild);
127        assertEquals(1, buildTimeoutHandler.getCurrentBuildsInConsideration());
128        // invoke scheduler twice for this test (should return 13s and 38s of 45s timeout)
129        manualScheduler.invoke();
130        manualScheduler.invoke();
131        // finish build early
132        buildEventListener.beforeBuildFinish(mockSRunningBuild);
133        assertEquals(1, memoryAppenderBuildTimeoutHandler.search(String.format("%s finished and will no longer be considered.", mockSRunningBuild)).size());
134        // invoke again after build has finished verifying that there are no builds in consideration anymore
135        manualScheduler.invoke();
136        assertEquals(1, memoryAppenderBuildTimeoutHandler.search("No builds to check, quitting early").size());
137        assertEquals(0, buildTimeoutHandler.getCurrentBuildsInConsideration());
138    }
139    @Test
140    // add build with too few builds in history; nothing should happen
141    void addBuildWithoutHistory() {
142        final SRunningBuild mockSRunningBuild = context.mock(SRunningBuild.class);
143        final Map<String, String> elasticTimeoutFailureConditionParameters = failureCondition.getDefaultParameters();
144        final SFinishedBuild mockSFinishedBuild = context.mock(SFinishedBuild.class);
145
146        context.checking(new Expectations() {
147            {
148                // get called twice, once while adding (buildStarted) and once while removing (beforeBuildFinish)
149                atLeast(2).of(mockSRunningBuild).getBuildFeaturesOfType(ElasticTimeoutFailureCondition.TYPE); will (returnValue(Collections.singleton(mockSBuildFeatureDescriptor)));
150                oneOf(mockSBuildFeatureDescriptor).getParameters(); will (returnValue(elasticTimeoutFailureConditionParameters));
151                // based on plugins default settings we add three builds to the history and querying accordingly three times the duration (returning different values each time)
152                oneOf(buildHistory).getEntriesBefore(mockSRunningBuild, true); will (returnValue(Arrays.asList(mockSFinishedBuild, mockSFinishedBuild)));
153            }
154        });
155        buildEventListener.buildStarted(mockSRunningBuild);
156        // since there are just two builds in history this build shouldn't be considered
157        assertEquals(0, buildTimeoutHandler.getCurrentBuildsInConsideration());
158        assertEquals(1, memoryAppenderBuildTimeoutHandler.search(String.format("[%s] has elastic timout enabled but doesn't have enough builds in history to consider (%d/%d). Skipping...", mockSRunningBuild, 2, 3)).size());
159    }
160    @Test
161    // add build, run into timeout and test if build stopped and got removed from map
162    // could think about testing history with "any" build but since its mocked anyway it doesn't make so much sense
163    void stopBuild() {
164        final SRunningBuild mockSRunningBuild = context.mock(SRunningBuild.class);
165        final Map<String, String> elasticTimeoutFailureConditionParameters = failureCondition.getDefaultParameters();
166        final SFinishedBuild mockSFinishedBuild = context.mock(SFinishedBuild.class);
167
168        context.checking(new Expectations() {
169            {
170                // get called twice, once while adding (buildStarted) and once while removing (beforeBuildFinish)
171                atLeast(2).of(mockSRunningBuild).getBuildFeaturesOfType(ElasticTimeoutFailureCondition.TYPE); will (returnValue(Collections.singleton(mockSBuildFeatureDescriptor)));
172                oneOf(mockSBuildFeatureDescriptor).getParameters(); will (returnValue(elasticTimeoutFailureConditionParameters));
173                // based on plugins default settings we add three builds to the history and querying accordingly three times the duration (returning different values each time)
174                oneOf(buildHistory).getEntriesBefore(mockSRunningBuild, true); will (returnValue(Arrays.asList(mockSFinishedBuild, mockSFinishedBuild, mockSFinishedBuild)));
175                atLeast(3).of (mockSFinishedBuild).getDuration();
176                will(onConsecutiveCalls(
177                        returnValue(10L),
178                        returnValue(20L),
179                        returnValue(30L)));
180                // get called twice, within scheduler and once while removing
181                atLeast(2).of(mockSRunningBuild).getBuildId(); will (returnValue(1L));
182                // get invoked twice within scheduler, and return below timeout value (45s)
183                atLeast(2).of(runningBuildsManager).findRunningBuildById(1L); will (returnValue(mockSRunningBuild));
184                atLeast(2).of(mockSRunningBuild).getDuration();
185                will(onConsecutiveCalls(
186                        returnValue(13L),
187                        returnValue(46L)));
188                oneOf(mockSRunningBuild).stop(with(any(DummyUser.class)), with(any(String.class)));
189                oneOf(mockSRunningBuild).addBuildProblem(with(any(BuildProblemData.class)));
190            }
191        });
192        buildEventListener.buildStarted(mockSRunningBuild);
193        assertEquals(1, buildTimeoutHandler.getCurrentBuildsInConsideration());
194        // invoke scheduler twice for this test (should return 13s and 46s of 45s timeout)
195        manualScheduler.invoke();
196        // this should result in timeout
197        manualScheduler.invoke();
198        assertEquals(0, buildTimeoutHandler.getCurrentBuildsInConsideration());
199        assertEquals(1, memoryAppenderBuildTimeoutHandler.search(String.format("%s is running already %d and exceed maximum allowed time of %d and got stopped.", mockSRunningBuild, 46, 45)).size());
200        // simulate finishing event and check again on log
201        buildEventListener.beforeBuildFinish(mockSRunningBuild);
202        assertEquals(1, memoryAppenderBuildTimeoutHandler.search(String.format("%s was removed earlier already from consideration due to timeout.", mockSRunningBuild)).size());
203        manualScheduler.invoke();
204        assertEquals(1, memoryAppenderBuildTimeoutHandler.search("No builds to check, quitting early").size());
205    }
206    @Test
207    // add build, don't stop and check if build problem was added and if it got removed from map
208    void addJustBuildProblem() {
209        final SRunningBuild mockSRunningBuild = context.mock(SRunningBuild.class);
210        final Map<String, String> elasticTimeoutFailureConditionParameters = failureCondition.getDefaultParameters();
211        // switch param to not stop build (but just add build problem)
212        elasticTimeoutFailureConditionParameters.put(PARAM_STOP_BUILD, "false");
213        final SFinishedBuild mockSFinishedBuild = context.mock(SFinishedBuild.class);
214        context.checking(new Expectations() {
215            {
216                // get called twice, once while adding (buildStarted) and once while removing (beforeBuildFinish)
217                atLeast(2).of(mockSRunningBuild).getBuildFeaturesOfType(ElasticTimeoutFailureCondition.TYPE); will (returnValue(Collections.singleton(mockSBuildFeatureDescriptor)));
218                oneOf(mockSBuildFeatureDescriptor).getParameters(); will (returnValue(elasticTimeoutFailureConditionParameters));
219                // based on plugins default settings we add three builds to the history and querying accordingly three times the duration (returning different values each time)
220                oneOf(buildHistory).getEntriesBefore(mockSRunningBuild, true); will (returnValue(Arrays.asList(mockSFinishedBuild, mockSFinishedBuild, mockSFinishedBuild)));
221                atLeast(3).of (mockSFinishedBuild).getDuration();
222                will(onConsecutiveCalls(
223                        returnValue(10L),
224                        returnValue(20L),
225                        returnValue(30L)));
226                // get called twice, within scheduler and once while removing
227                atLeast(2).of(mockSRunningBuild).getBuildId(); will (returnValue(1L));
228                // get invoked twice within scheduler, and return below timeout value (45s)
229                atLeast(2).of(runningBuildsManager).findRunningBuildById(1L); will (returnValue(mockSRunningBuild));
230                atLeast(2).of(mockSRunningBuild).getDuration();
231                will(onConsecutiveCalls(
232                        returnValue(13L),
233                        returnValue(46L)));
234                oneOf(mockSRunningBuild).addBuildProblem(with(any(BuildProblemData.class)));
235            }
236        });
237        buildEventListener.buildStarted(mockSRunningBuild);
238        assertEquals(1, buildTimeoutHandler.getCurrentBuildsInConsideration());
239        // invoke scheduler twice for this test (should return 13s and 46s of 45s timeout)
240        manualScheduler.invoke();
241        // this should result in timeout
242        manualScheduler.invoke();
243        assertEquals(0, buildTimeoutHandler.getCurrentBuildsInConsideration());
244        assertEquals(1, memoryAppenderBuildTimeoutHandler.search(String.format("%s is running already %d and exceed maximum allowed time of %d and got annotated with build problem.", mockSRunningBuild, 46, 45)).size());
245        // simulate finishing event and check again on log
246        buildEventListener.beforeBuildFinish(mockSRunningBuild);
247        assertEquals(1, memoryAppenderBuildTimeoutHandler.search(String.format("%s was removed earlier already from consideration due to timeout.", mockSRunningBuild)).size());
248        manualScheduler.invoke();
249        assertEquals(1, memoryAppenderBuildTimeoutHandler.search("No builds to check, quitting early").size());
250    }
251    @Test
252    void testPercentageCalculation() {
253        // add build and test timeout based on percentage calculations
254    }
255    @Test
256    void testFixedValueCalculation() {
257        // add build and test timeout based on fixed values calculations
258    }
259}
260
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)