serenity-bdd / serenity-gradle-plugin

Apache License 2.0
1 stars 11 forks source link

Environment variables read only during first gradle run #9

Open gallardo opened 2 years ago

gallardo commented 2 years ago

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 git@github.com: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 commented 2 years ago

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