-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix flaky tests and fix passDefaultLocalCheck (#3367)
* fix test case SentinelDubboConsumerFilterTest#testDegradeSync * When test is run slow, count bucket will count on next time span, causing failed test. * dos2unix ParamFlowDefaultCheckerTest.java * fix testParamFlowDefaultCheckSingleValueCheckQpsMultipleThreads by rule.setDurationInSec(2) * set threshold as count in 2 seconds to prevent the failure of the unit test when the unit test runs longer than 1 second. * fix quarkus test by set /txt sleep 300 * If /txt sleep 500 ms, in testSentinelJaxRsQuarkusAdapter, may cause 2 request intervals of more than 1 s, which cause rate limit policy is not effective. * fix testDegradeAsync * When test is run slow, count bucket will count on next time span, causing failed test. * use testcontainers to fix testConsulDataSourceWhenInit * Project embedded-consul has been deprecated in favour of org.testcontainers:consul * use consul testcontainers to fix testConsulDataSourceWhenInit, which means docker is required to run tests. ``` Error: com.alibaba.csp.sentinel.datasource.consul.ConsulDataSourceTest.testConsulDataSourceWhenInit -- Time elapsed: 34.47 s <<< ERROR! com.pszymczyk.consul.EmbeddedConsulException: Could not start Consul process in 30 seconds at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:72) ``` * introduce intermediate node to avoid ABA problem
- Loading branch information
1 parent
befdc56
commit cd02b1d
Showing
18 changed files
with
650 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...o-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo/AbstractTimeBasedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 1999-2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.csp.sentinel.adapter.dubbo; | ||
|
||
import com.alibaba.csp.sentinel.util.TimeUtil; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
|
||
public abstract class AbstractTimeBasedTest { | ||
|
||
private long currentMillis = 0; | ||
|
||
public MockedStatic<TimeUtil> mockTimeUtil() { | ||
MockedStatic<TimeUtil> mocked = Mockito.mockStatic(TimeUtil.class); | ||
mocked.when(TimeUtil::currentTimeMillis).thenReturn(currentMillis); | ||
return mocked; | ||
} | ||
|
||
protected final void useActualTime(MockedStatic<TimeUtil> mocked) { | ||
mocked.when(TimeUtil::currentTimeMillis).thenCallRealMethod(); | ||
} | ||
|
||
protected final void setCurrentMillis(MockedStatic<TimeUtil> mocked, long cur) { | ||
currentMillis = cur; | ||
mocked.when(TimeUtil::currentTimeMillis).thenReturn(currentMillis); | ||
} | ||
|
||
protected final void sleep(MockedStatic<TimeUtil> mocked, long timeInMs) { | ||
currentMillis += timeInMs; | ||
mocked.when(TimeUtil::currentTimeMillis).thenReturn(currentMillis); | ||
} | ||
|
||
protected final void sleepSecond(MockedStatic<TimeUtil> mocked, long timeSec) { | ||
sleep(mocked, timeSec * 1000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...-adapter/src/test/java/com/alibaba/csp/sentinel/adapter/dubbo3/AbstractTimeBasedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 1999-2024 Alibaba Group Holding Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.alibaba.csp.sentinel.adapter.dubbo3; | ||
|
||
import com.alibaba.csp.sentinel.util.TimeUtil; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.Mockito; | ||
|
||
public abstract class AbstractTimeBasedTest { | ||
|
||
private long currentMillis = 0; | ||
|
||
public MockedStatic<TimeUtil> mockTimeUtil() { | ||
MockedStatic<TimeUtil> mocked = Mockito.mockStatic(TimeUtil.class); | ||
mocked.when(TimeUtil::currentTimeMillis).thenReturn(currentMillis); | ||
return mocked; | ||
} | ||
|
||
protected final void useActualTime(MockedStatic<TimeUtil> mocked) { | ||
mocked.when(TimeUtil::currentTimeMillis).thenCallRealMethod(); | ||
} | ||
|
||
protected final void setCurrentMillis(MockedStatic<TimeUtil> mocked, long cur) { | ||
currentMillis = cur; | ||
mocked.when(TimeUtil::currentTimeMillis).thenReturn(currentMillis); | ||
} | ||
|
||
protected final void sleep(MockedStatic<TimeUtil> mocked, long timeInMs) { | ||
currentMillis += timeInMs; | ||
mocked.when(TimeUtil::currentTimeMillis).thenReturn(currentMillis); | ||
} | ||
|
||
protected final void sleepSecond(MockedStatic<TimeUtil> mocked, long timeSec) { | ||
sleep(mocked, timeSec * 1000); | ||
} | ||
} |
Oops, something went wrong.