Reactor-core: Context is not propagated in Junit5 nested class

Created on 31 Oct 2018  路  12Comments  路  Source: reactor/reactor-core

Expected behavior

Both tests pass

Actual behavior

Only test in main class pass

Steps to reproduce

Run the test:

@ExtendWith(SpringExtension.class)
@TestExecutionListeners(MockitoTestExecutionListener.class)
class ContextTest {

    @Nested
    class Nest {

        @Test
        void testContext() {
          StepVerifier.create(Mono.just(1).map(i -> i + 10),
          StepVerifierOptions.create().withInitialContext(Context.of("foo", "bar")))
              .expectAccessibleContext()
              .contains("foo", "bar")
              .then()
              .expectNext(11)
              .verifyComplete();
        }
    }

    @Test
    void testContext() {
      StepVerifier.create(Mono.just(1).map(i -> i + 10),
      StepVerifierOptions.create().withInitialContext(Context.of("foo", "bar")))
          .expectAccessibleContext()
          .contains("foo", "bar")
          .then()
          .expectNext(11)
          .verifyComplete();
    }
}

Reactor Core version

3.2.0.RELEASE

JVM version (e.g. java -version)

9.0.4

statuneed-investigation typbug

Most helpful comment

I can confirm that the error does not occur with version 3.2.3
Thanks!

All 12 comments

Ok, solved. You need to add ReactorContextTestExecutionListener.class to @TestExecutionListeners

False alarm, it made things even worse...

Hi @eximius313,

Thanks for your report! I tried to run the code you provided but I did not observe any test failure, both are passing.

Could you please provide more information about your environment?
e.g. I see SpringExtension and Mockito's extension, which versions of both are you using?

Thank you!

Hi @bsideup , thanks for your response.

We use spring-test 5.1.0.RELEASE and spring-boot-test:2.1.0.M4

The nested test fails with reason: java.lang.AssertionError: No propagated Context

@anilewek does it also fail if you update to the release version of spring-boot-test (2.1.0.RELEASE)?

@bsideup yes, it still fails with the same error.

Ok, I was able to reproduce it, but only when 'org.springframework.security:spring-security-test' is added to the classpath.
@anilewek could you please confirm that you have it?

Meanwhile, I'll check with Spring Security folks why it happens.

I confim (I have it as transitive dependency)

Ok, @Nested is not the cause.

Reproduced with:

@ExtendWith(SpringExtension.class)
class ContextTest {

    @Test
    void testContext() {
        StepVerifierOptions stepVerifierOptions = StepVerifierOptions.create()
                .withInitialContext(Context.of("foo", "bar"));

        StepVerifier.create(Mono.just(1), stepVerifierOptions)
                .expectAccessibleContext()
                .contains("foo", "bar")
                .then()
                .verifyComplete();
    }
}

it works if you annotate test class with @TestExecutionListeners(MockitoTestExecutionListener.class) but fails without it. Will check why.

@eximius313 @anilewek it also means that you can temporary workaround the bug by annotating your nested class with @TestExecutionListeners(MockitoTestExecutionListener.class)

Thanks

Hi @eximius313,

Was about to follow up :)

I think we were able to identify the problem and the fix will be included in the next release.
Meanwhile, it would be nice if you can test it with a SNAPSHOT version:
https://projectreactor.io/docs/core/release/reference/index.html#_milestones_and_snapshots

Thanks!

I can confirm that the error does not occur with version 3.2.3
Thanks!

Was this page helpful?
0 / 5 - 0 ratings