schananas / practical-reactor

Practical Project Reactor and reactive programing workshop
MIT License
387 stars 757 forks source link

Can't pass exercise c4_LifecycleHooks need_to_cancel when upgrade reactor-core package. #7

Closed cnhongwei closed 2 years ago

cnhongwei commented 2 years ago

I use the code below

        AtomicBoolean canceled = new AtomicBoolean(false);

        Flux<Integer> temperatureFlux = room_temperature_service()
                .doOnCancel(() -> canceled.set(true)) //todo: change this line only
                ;

        StepVerifier.create(temperatureFlux.take(0))
                    .expectNextCount(0)
                    .verifyComplete();

        Assertions.assertTrue(canceled.get());

The test case can pass when i use reactor-core:3.4.14. But it can't pass when is use reactor-core:3.5.0-m2. Is this a bug of reactor-core:3.5.0-m2 or has the behavior changed on eactor-core:3.5.0-m2? I don't know how to fix it.

schananas commented 2 years ago

Hi, thanks for reporting this issue. It might be due to change of behavior in next major version, but since it's a milestone version it's early for me to support it. Is there a specific reason why you are using milestone versions? I didn't try it but looks like you may resolve it if you change take(0) to take(1) and expectNextCount(0) to expectNextCount(1)

cnhongwei commented 2 years ago

It works. Thank you very much. I use the milestone version because i start learn spring boot 3.