swagger-play
swagger-play copied to clipboard
Disable swagger when in test mode for compiler(Unittest/Specs2) [Play framework Java/Scala]
From @ghost on June 11, 2014 15:26
Is it possible to make swagger disable if you run unittests in for example Specs2 so the tests will run a lot faster?
Copied from original issue: swagger-api/swagger-core#594
From @fehguy on June 11, 2014 20:42
Can you elaborate more?
From @ghost on June 12, 2014 8:8
In what way are you asking this? Hope its not sarcastic. Because i'm just trying to make myself as clear as possible.
From @fehguy on June 12, 2014 16:18
um, no, i'm quite serious. are you talking about building swagger-core, your sample project, an integration test, a unit test, or what?
From @ghost on June 19, 2014 9:26
Sorry for my later response. I've been very busy lately.
If you run Play it starts with a "mode". This can be Dev/Test/Prod. Test mode wil be triggered if you run Unittests, intergration test or a Specs2(plugin for unit specifications and acceptance specifications). In test mode there is no need for swagger. But it will be triggered and the tests will be slowed down by swagger.
I Have managed to interupt swagger from running in testmode by adding "swagger.api.basepath=nonvalidurl" in the config file. This is a really dirty solution. i know :(
From @mauhiz on October 3, 2014 4:59
How slower does Swagger make things, exactly? Is scanning the annotations the slow part?
From @lammel on December 1, 2014 11:23
We are facing the same issue here. The annotation scanning results in a slowdown of our suite with 1000 tests considerable (running over 20min instead of 2min). It seems laso the swagger plugin initialization is getting slower and slower as the tests progress.
If there is a sane way to disable swagger doing the same scanning over and over for the tests any hints would be greatly appreciated.
@lammel - can you give a few more details about your application? Is it servlet, jax-rs, play? How is swagger-core configured?
From @lammel on December 1, 2014 11:47
It's a play 2.3 application currently with Scala 2.10 using "com.wordnik" %% "swagger-play2" % "1.3.10". Tests do initialize the application afresh for most of the tests, so the scanning occurs pretty often. We basically followed the README, just adding the routes to api-docs and having currently 2 classes with annotations (about 20 routes).
No additional configuration for swagger-core. To which kind of configuration are you refering?
If it's Play then perhaps @fehguy will be able to assist. I'm not that familiar with the Play integration.
From @lammel on December 1, 2014 12:26
Thanks, let's see if @fehguy has some time to spare for an answer. I just tried with swagger-play2 1.3.11. I'm still seeing a notable slowdown of plugin initialization after some tests (pretty fast initially at 160ms and slows down to approx 600ms after 50 tests and keeps on growing up to 2-3 seconds).
Memory has been checked (using jvisualvm), still memory free and permgen is also fine (both having approx 40% free).
Seems like computation requires more and more effort with each application init for testing.
From @fehguy on December 3, 2014 6:9
Hi, the SwaggerPlugin.scala is calling onStop(), which is clearing the cache. My guess is that the slow down is due to garbage being generated and not cleaned up off the heap?
override def onStop() {
ApiListingCache.cache = None
Logger("swagger").info("Plugin - stopped");
}
From @lammel on December 4, 2014 16:14
Ok, so I would need to patch (comment out) that to verify. I see if I get around to doing that.
From @fehguy on December 23, 2014 22:49
We'll investigate and see if this can be done in the 1.5.0-M3 release.
From @mikalveli on December 24, 2014 4:8
I actually had this same problem today using the swagger-play2 plugin. In Play, you can disable plugins when using fakeApplication(). Here is the signature of the method:
public static FakeApplication fakeApplication(Map<String, ? extends Object> additionalConfiguration, List<String> additionalPlugins, List<String> withoutPlugins)
So in my particular case I'm using this call for each of my integration tests:
running(testServer(3333, fakeApplication(InMemoryDatabase.inMemoryDatabase(), new ArrayList<String>(), Arrays.asList("play.modules.swagger.SwaggerPlugin"))), HTMLUNIT, browser -> {
From @lammel on December 25, 2014 22:49
Ah, great, thanks! Should have looked more into FakeApplication instead of messing with the sbt plugin config. Using withoutPlugins for FakeApplikation works great and is looks to me like the right solution anyway.
If it should be documented I can provide a pull request for the text blurb. Any specific place where we should put that (e.g. readme)? This should probably be documented, is there a place to put this (e.g. readme)?
@fehguy - How is this related to the 1.5.X releases?
I would be curious if this is any better/worse for swagger-play 1.5.0 that was just released for Play 2.4. It parses information from the routes file and does less scanning of annotations, which was indicated to be the slow part.
Just upgraded to 1.5.2. It is way better than before. Still tests are running twice as long when swagger is enabled so I chose again to disable it for now in tests.
We are running Play 2.4 with DI now, so we disable by configuring the fake application with "play.modules.disabled" to include "play.modules.swagger.SwaggerModule".