Skip to content
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

Merged
merged 1 commit into from
Jun 17, 2021

Conversation

realJackSun
Copy link
Collaborator

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:

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test to verify your logic correction, more mock a little better when cross module dependency exist. If the new feature or significant change is committed, please remember to add integration-test in test module.
  • Run mvn -B clean package apache-rat:check findbugs:findbugs -Dmaven.test.skip=true to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.

@realJackSun realJackSun force-pushed the fix5983 branch 3 times, most recently from 19e501e to bb57981 Compare June 15, 2021 12:04
@@ -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);
Copy link
Collaborator Author

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重置为原先的值。

Copy link
Collaborator

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")
Copy link
Collaborator Author

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;
能够扫描到所有的依赖。如果不加就会出现依赖找不到的错误。

Copy link
Collaborator

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 @@
#
Copy link
Collaborator Author

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);
Copy link
Collaborator

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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

无法mock?

@KomachiSion
Copy link
Collaborator

Please pull newest codes, which fix ci problem.

@KomachiSion KomachiSion merged commit c13f800 into alibaba:develop Jun 17, 2021
@realJackSun realJackSun deleted the fix5983 branch June 18, 2021 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix unit tests in nacos-config
2 participants