[BUG] ClientFilterTest and ProviderFilterTest have order dependent tests
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
## Issue Description
Type: *bug report*
### Describe what happened
- In `com.alibaba.csp.sentinel.adapter.jaxrs.ClientFilterTest`, the unit test `testClientFallback()` will fail when run after the unit test `testClientCustomFallback()`.
- Similarly, the following unit tests in `com.alibaba.csp.sentinel.adapter.jaxrs.ProviderFilterTest` will fail when run after the unit test `testCustomFallback()`
- `com.alibaba.csp.sentinel.adapter.jaxrs.ProviderFilterTest.testDefaultFallback()`
- `com.alibaba.csp.sentinel.adapter.jaxrs.ProviderFilterTest.testCustomRequestOriginParser()`
- This is because the tests `ClientFilterTest.testClientCustomFallback()` and `ProviderFilterTest.testCustomFallback()` pollute the shared state `SentinelJaxRsConfig.jaxRsFallback` between tests at
https://github.com/alibaba/Sentinel/blob/5108046ba2bb5371841caedd6f5e9b5d47c52827/sentinel-adapter/sentinel-jax-rs-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/jaxrs/ClientFilterTest.java#L233
https://github.com/alibaba/Sentinel/blob/5108046ba2bb5371841caedd6f5e9b5d47c52827/sentinel-adapter/sentinel-jax-rs-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/jaxrs/ProviderFilterTest.java#L168
- However, this state isn't cleaned after the run causing the above mentioned tests to fail
### Describe what you expected to happen
- The unit tests in `com.alibaba.csp.sentinel.adapter.jaxrs.ClientFilterTest` and `com.alibaba.csp.sentinel.adapter.jaxrs.ProviderFilterTest` should pass when run in any order
### How to reproduce it (as minimally and precisely as possible)
- In `com.alibaba.csp.sentinel.adapter.jaxrs.ClientFilterTest`, run the following unit tests in order
- `testClientCustomFallback()`
- `testClientFallback()`
- In `com.alibaba.csp.sentinel.adapter.jaxrs.ProviderFilterTest`, run the following unit tests in order
- `testCustomFallback()`
- `testDefaultFallback()` or `testCustomRequestOriginParser()`
- Running the tests in the above manner will produce `java.lang.AssertionError`
```
java.lang.AssertionError:
Expected :429
Actual :200
at org.junit.Assert.fail(Assert.java:88)
at org.junit.Assert.failNotEquals(Assert.java:834)
at org.junit.Assert.assertEquals(Assert.java:645)
at org.junit.Assert.assertEquals(Assert.java:631)
at com.alibaba.csp.sentinel.adapter.jaxrs.ClientFilterTest.testClientFallback(ClientFilterTest.java:224)
```
- The exact stacktrace will vary based on the second test executed
### Tell us your environment
- Sentinel: `1.8.6`
- OS: `Mac OS X 14.0 aarch64`
- Java: `17.0.9` or `1.8.0_381`
### Anything else we need to know?
- I have raised a PR #3272 to fix this issue by resetting the polluter state `SentinelJaxRsConfig.jaxRsFallback` to its default value in the `cleanUp()` method of the respective classes.
Contributor guide
Assessment
This issue has not been assessed yet.