-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#5983] Fix unit tests in nacos-config #5995
Conversation
19e501e
to
bb57981
Compare
@@ -84,6 +84,9 @@ public void onEvent(Event event) { | |||
Thread.sleep(2000); | |||
Assert.assertNotNull(reference.get()); | |||
reference.set(null); | |||
|
|||
EnvUtil.setIsStandalone(true); | |||
PropertyUtil.setEmbeddedStorage(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个修改的动机是,这个单测会通过EnvUtil.setIsStandalone(false);破坏原来的EnvUtil的字段值。
这里两行代码,将EnvUtil重置为原先的值。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在Before方法和After方法中去还原。否则异常情况下仍然会导致不会重制。
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringBootTest | ||
@SpringBootApplication(scanBasePackages = "com.alibaba.nacos") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个和@lzf核对了一下,这个是为了让DumpServiceTest中的
@Autowired DumpService service;
能够扫描到所有的依赖。如果不加就会出现依赖找不到的错误。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
无法mock?
@@ -0,0 +1,36 @@ | |||
# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加上这个配置文件的意义在于,没有这个配置文件,DumpServiceTest的前置@SpringBootTest就启动不了。
@@ -84,6 +84,9 @@ public void onEvent(Event event) { | |||
Thread.sleep(2000); | |||
Assert.assertNotNull(reference.get()); | |||
reference.set(null); | |||
|
|||
EnvUtil.setIsStandalone(true); | |||
PropertyUtil.setEmbeddedStorage(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在Before方法和After方法中去还原。否则异常情况下仍然会导致不会重制。
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringBootTest | ||
@SpringBootApplication(scanBasePackages = "com.alibaba.nacos") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
无法mock?
Please pull newest codes, which fix ci problem. |
fix #5983
What is the purpose of the change
XXXXX
Brief changelog
XX
Verifying this change
XXXX
Follow this checklist to help us incorporate your contribution quickly and easily:
[ISSUE #123] Fix UnknownException when host config not exist
. Each commit in the pull request should have a meaningful subject line and body.mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true
to make sure basic checks pass. Runmvn clean install -DskipITs
to make sure unit-test pass. Runmvn clean test-compile failsafe:integration-test
to make sure integration-test pass.