Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add timeout of Step and Scenario #343

Closed
k4124k opened this issue Jun 13, 2012 · 11 comments
Closed

feature: add timeout of Step and Scenario #343

k4124k opened this issue Jun 13, 2012 · 11 comments

Comments

@k4124k
Copy link

k4124k commented Jun 13, 2012

timeout of step or scenario could be used for assert time of duration

@aslakhellesoy
Copy link
Contributor

How would you like to specify a timeout? Code please.

@k4124k
Copy link
Author

k4124k commented Jun 16, 2012

eg1:
Given("xxxx",3000){
//step code
}
eg2:
Given(
"xxxx"){
System.setProperty("timeout",1000)
//step code
}

@aslakhellesoy
Copy link
Contributor

Can you give some example of long-running activity that might happen in a step definition that you would want to time out?

@paul8620
Copy link

Well I've run into this and found an issue.
I am supposed to test a service, while the service does it's logic I have manage to create an infinite loop. I've used https://code.google.com/p/rest-assured/ API toghether with cucumber and unfortunate to me none of the timeouts worked, until I've created a separate thread for the REST call. Then the cucumber thread worked.
What I expect from this feature is that even if i don't create a separate thread to run the rest call the timeout to work.
However the timeout works only if the thread is at sleep for the number of milliseconds presented in the timeout. What I want from this feature is to assert a certain duration of the test.

Eg. If I know that a certain step is taking 1 minute to execute at most. Then if the step is not executed in that 1 minute the step should timeout.

Excuse me if I'm referring to a new feature, and didn't understood the timeout feature written here.

@aslakhellesoy
Copy link
Contributor

I recommend you take a look at TimeoutTest and Timeout and see if you can modify them to reproduce the behaviour you're seeing.

aslakhellesoy added a commit that referenced this issue Dec 17, 2014
If a thread does not respond to interrupt() we'll
try to stop() it after twice the specified timeout.

This uses the deprecated Thread.stop() method, but
for a testing tool like Cucumber that should be ok.

Ref #343.
@paul8620
Copy link

Well it's an ok approach not the best.

@aslakhellesoy
Copy link
Contributor

@paul8620 what would be a better approach in your opinion?

@paul8620
Copy link

First this is what actually happens
Update TimeoutTest with this method and update Slow class with infiniteLoop

public class TimeoutTest {
    @Test(expected = TimeoutException.class)
    public void times_out_on_infinite_loop() throws Throwable {
        final Slow slow = new Slow();
        Timeout.timeout(new Timeout.Callback<Void>() {
            @Override
            public Void call() throws Throwable {
                slow.infiniteLoop();
                return null;
            }
        }, 10);
        fail();
    }
}
    public static class Slow {
        public String slow(int millis) throws InterruptedException {
            sleep(millis);
            return String.format("slept %sms", millis);
        }
        public void infiniteLoop(){
            while(true)
            {

            }
        }

        public void infinite() throws InterruptedException {
            while (true) {
                sleep(1);
            }
        }

        public void infiniteLatchWait() throws InterruptedException {
            new CountDownLatch(1).await();

@paul8620
Copy link

You should implement a timeout that lasts the specified timeout not twice the amount of timeout :D

@aslakhellesoy
Copy link
Contributor

@paul8620 Can you format your code with GFM please? I can't read it.
Have you looked at the latest revision of Timeout/TimeoutTest?

The reason I'm doubling the timeout is that we want to give it a chance to interrupt the thread before stopping it. Stopping the thread is a last resort strategy.

I think what we really need to do is to look at how this is implemented in JUnit. They seem to have a solution that works.

Let's continue the discussion in #811 - this issue is closed.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
mpkorstanje pushed a commit that referenced this issue Oct 4, 2019
…fter which a is thrown if the stepdef/hook has not completed. Closes #343
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants