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

Environment variables read only during first gradle run #9

Open
gallardo opened this issue May 19, 2022 · 1 comment
Open

Environment variables read only during first gradle run #9

gallardo opened this issue May 19, 2022 · 1 comment

Comments

@gallardo
Copy link
Contributor

Description

Environment variables are read only during first gradle run. Subsequent runs ignore changes.

Steps to reproduce

(I've omitted superfluous output and used ellipsis ... to shorten output)
(I'm invoking explicitly clearReports and aggregate to avoid distractions due to a fixed plugin issue)

  1. Make sure you have a working test set and a valid serenity configuration, and that no gradle daemon is running:

    $ git clone [email protected]:serenity-bdd/serenity-junit-starter.git
    Cloning into 'serenity-junit-starter'...
    ...
    $ cd serenity-junit-starter/
    $ git checkout 5d5b01a
    ...
    HEAD is now at 5d5b01a Merge pull request #26 from mariagomgod/master
    $ ./gradlew --stop
    

    This should generate valid reports:

    $ ./gradlew clean clearReports test aggregate
    ...
    BUILD SUCCESSFUL in 25s
    6 actionable tasks: 5 executed, 1 up-to-date
    

    Features should appear in index.html 3 times:

    $ grep 'Features' target/site/serenity/index.html | wc -l
    3
    
  2. Kill all gradle daemons

    $ ./gradlew --stop
    ...
    1 Daemon stopped
    
  3. Change serenity.test.root to something invalid and create reports

    $ sed "s/starter/starterXXX/" -i src/test/resources/serenity.conf 
    $ ./gradlew clean clearReports test aggregate
    

    When broken, Features is not present in index.html (this is expected)

    $ grep 'Features' target/site/serenity/index.html | wc -l
    0
    
  4. Set serenity.test.root back to its correct value and create reports again

    $ sed "s/starterXXX/starter/" -i src/test/resources/serenity.conf 
    $ ./gradlew clean clearReports test aggregate
    

    Features should appear in index.html 3 times. These reports are broken! (unexpected)

    $ grep 'Features' target/site/serenity/index.html | wc -l
    0
    
  5. Create reports outside the gradle daemon

    $ ./gradlew --no-daemon clean clearReports test aggregate
    

    These reports looks OK (expected):

    $ grep 'Features' target/site/serenity/index.html | wc -l
    3
    

Analysis

Since gradle 3.0+ is the gradle daemon enabled by default (see https://docs.gradle.org/3.0/release-notes.html#improved-gradle-daemon,-now-enabled-by-default), and the plugin is run inside gradle's jvm. Unfortunately the configuration is created by guice as singleton only during first run and subsequent invocations of the plugin reuse the configuration.

@wakaleo
Copy link
Member

wakaleo commented May 19, 2022

Hmmm, not sure what to do about this. Maybe add the ability to reload the EnvironmentVariables at the start of each test?

gallardo added a commit to gallardo/serenity-gradle-plugin that referenced this issue May 31, 2022
Due to gradle starting by default as daemon and many services configured guice singletons, configuration is read only on first gradle run. If these services are not explicitly reset, serenity configuration changes are ignored on subsequent gradle runs.

This commit fixes serenity-bdd#9. It instructs guice to recreate many of these services when they are requested instead of reusing them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants