0

I'm getting desperate on a few tests classes. I think I kind of narrowed down the problem but I'm out of ideas for how to fix it.

TLDR: how to properly tear down a DropwizardAppRule instance in order to use a different one in another class?
Or maybe force a configured bundle to refresh from the rule ?


To test two different configurations of our application (a configured bundle is slightly changing according to configuration file), I instantiate two DropwizardAppRule with different configuration files in my tests. The tests run fine if run alone, but there are errors if they don't run one after another in the "Correct" order.

The error looks like a side effect, I guess I was not able to cleanly restart DropwizardAppRule with another config.
I started by making custom rule extending the first one, then separate rules implementing TestRule (both instanciating DropwizardAppRule), I tried using JUnit @After, tried adding after rules, tried closing stuff in the life-cycle ... until I ran out of ideas.

I finally went back to Rules extending each other: CockpitLdapApplicationRule extends CockpitApplicationRule and worked around by putting Ldap tests in a package starting by "z" and setting maven to run tests in alphabetical order ...

I created a branch if someone cares to take a look at it.

The error :

org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyReader not found for media type=text/html;charset=iso-8859-1, type=class org.ow2.petals.cockpit.server.resources.UserSession$CurrentUser, genericType=class org.ow2.petals.cockpit.server.resources.UserSession$CurrentUser.
 at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$TerminalReaderInterceptor.aroundReadFrom(ReaderInterceptorExecutor.java:231)
 at org.glassfish.jersey.message.internal.ReaderInterceptorExecutor.proceed(ReaderInterceptorExecutor.java:155)
 at org.glassfish.jersey.message.internal.MessageBodyFactory.readFrom(MessageBodyFactory.java:1085)
 at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:874)
 at org.glassfish.jersey.message.internal.InboundMessageContext.readEntity(InboundMessageContext.java:808)
 at org.glassfish.jersey.client.ClientResponse.readEntity(ClientResponse.java:326)
 at org.glassfish.jersey.client.InboundJaxrsResponse$1.call(InboundJaxrsResponse.java:115)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
 at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
 at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:419)
 at org.glassfish.jersey.client.InboundJaxrsResponse.runInScopeIfPossible(InboundJaxrsResponse.java:267)
 at org.glassfish.jersey.client.InboundJaxrsResponse.readEntity(InboundJaxrsResponse.java:112)
 at org.ow2.petals.cockpit.server.security.UserSessionTest.testLogout(UserSessionTest.java:70)

I'm using Dropwizard 1.1.4.

To reproduce: a test suite that fails and another that succeeds, changing only the execution order.

Any input would be very appreciated at this point, I'm feeling like I'm looking in the wrong direction. I know it is a very vague question, I'll be happy to improve it with some inputs.

Thanks in advance!

Thom
  • 14,013
  • 25
  • 105
  • 185
Pierre
  • 111
  • 1
  • 4
  • Out of curiousity, do the tests pass if you run them outside of a Suite ? (i.e. you run use maven to run all tests individually) – matt freake Jul 26 '18 at 07:55
  • DropwizardAppRule *should* tear down the app when it's finished, so it's supect it's more likely that it's not running before and after each test, as you need, but only running before and after all-of-the-tests. Is it possible to confirm that by logging output when the rule rules, or using breakpoints within the DropwizardAppRule code? – matt freake Jul 26 '18 at 08:18
  • The Suites are just to reproduce. The test all pass individually (maven & eclipse), for them to pass when running everything I have to manipulate the execution order. They all succeed as long as those using DropwizardApp from CockpitApplicationRule run before those using from CockpitLdapApplicationRule. – Pierre Jul 26 '18 at 08:55
  • I added breakpoints and I go through DropwizardAppRule's constructor between each tests. I can try to track further inside, but I don't really know what is failing so I don't what to look for... Any proposition ? – Pierre Jul 26 '18 at 08:59
  • I was just a bit concerned by 'Using DropwizardAppRule at the suite level can speed up test runs, as the application is only started and stopped once for the entire suite: ' from the Javadoc – matt freake Jul 26 '18 at 10:59
  • Oh ok, could have been that. But it's not coming from the suites, I only added them to clearly reproduce the issue. I'm not using test suites on the project and it failed without them. And the rule is not used at Suite level anyway... – Pierre Jul 26 '18 at 11:07

0 Answers0