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

@Timed seems not to measure total time when used with @Repeat [SPR-6011] #10680

Closed
spring-projects-issues opened this issue Aug 16, 2009 · 2 comments
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Aug 16, 2009

Nils Wloka opened SPR-6011 and commented

Given the following component:

@Component
public class VerySlowKnowledgeBase implements KnowlegdeBase {

    public Iterable<Answer> findAnswersFor(Topic topic) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            // Nothing to do here
        }
        return null;
    }
}

the following test fails as expected:

@Test
@Timed(millis = 100)
public void popular_queries_should_yield_results_within_100_millis() {
    Topic topic = new SearchPhraseBasedTopic("Declarative Caching with Spring");
    Iterable<Answer> result = knowledgeBase.findAnswersFor(topic);
}

whereas this test passed even though it takes more than a second to do so:

@Repeat(10)
@Test
@Timed(millis = 1000)
public void popular_queries_should_yield_results_within_100_millis() {
    Topic topic = new SearchPhraseBasedTopic("Declarative Caching with Spring");
    Iterable<Answer> result = knowledgeBase.findAnswersFor(topic);
}

Also,

@Test
@Timed(millis = 400)
@Repeat(4)
public void popular_queries_should_yield_results_within_100_millis() {
    Topic topic = new SearchPhraseBasedTopic("Declarative Caching with Spring");
    Iterable<Answer> result = knowledgeBase.findAnswersFor(topic);
}

leads to

INFO: Repetition 1 of test SelectByTopicTest#popular_queries_should_yield_results_within_100_millis()
...
java.util.concurrent.TimeoutException: Test took 501 ms; limit was 400 ms.

which indicates that @Timed doesn't measure total execution time (as stated in the reference documentation).


Affects: 3.0 M3, 3.0 M4

Referenced from: commits a45d1de, 9845047

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Aug 28, 2009

Sam Brannen commented

Good catch, Nils!

We unfortunately did not have any tests in Spring's test suite that covered that exact usage, but I've just remedied that. ;)

In summary, SpringJUnit4ClassRunner once again supports collective timeouts for repeated tests.

Please give this a try with one of the upcoming nightly snapshots or Spring 3.0.0.RC1

cheers,

Sam

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 5, 2009

Nils Wloka commented

Hello Sam,

sorry for the late feedback. Works like intended with RC1.

Thanks,

Nils

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants