🌐 Background / 背景
EN: Currently, Nacos integration tests (IT) primarily rely on Spring Boot Test to construct the Nacos server instance. This approach has several significant drawbacks:
- Performance Issues: Multiple Spring container startups cause severe performance degradation
- Resource Contention: Static resources and configurations are prone to mutual interference between tests
- Test Isolation: Lack of proper isolation leads to flaky tests and unreliable results
CN: 当前 Nacos 的集成测试(IT)主要通过 Spring Boot Test 来构造 Nacos Server 实例,这种方式存在以下显著问题:
- 性能问题:多次启动 Spring 容器导致严重的性能下降
- 资源竞争:静态资源和配置容易在测试之间相互干扰
- 测试隔离性:缺乏适当的隔离导致测试不稳定且结果不可靠
The current IT implementation can be found at: https://github.com/alibaba/nacos/tree/develop/test
📦 Current State / 当前进展
EN: A prototype solution has been validated in a forked repository. The approach involves:
- Building Nacos server in CI/CD pipeline (GitHub Actions)
- Starting standalone Nacos server with embedded Derby database
- Running tests as pure JUnit tests without Spring Boot Test dependency
CN: 已在个人 fork 仓库中验证方案可行性,主要思路:
- 在 CI/CD 流水线(GitHub Actions)中构建 Nacos Server
- 启动单机版 Nacos Server(使用嵌入式 Derby 数据库)
- 测试用例不再依赖 Spring Boot Test,作为纯 JUnit 测试运行
Proof of Concept: A sample ConfigOpenAPI IT test class has been implemented to demonstrate the viability of this approach.
🎯 Migration Strategy / 迁移策略
| Aspect |
Current Approach |
Proposed Approach |
Benefits |
| Server Lifecycle |
Spring Boot Test per class |
Single server in CI |
Faster execution, less overhead |
| Database |
Mixed configurations |
Embedded Derby (Phase 1) |
Consistent test environment |
| Test Framework |
Spring Boot Test + JUnit |
Pure JUnit |
Reduced complexity, better isolation |
| Resource Management |
Shared Spring context |
External process |
No static resource conflicts |
🛠 Technical Proposal / 技术方案规划
Phase 1: Foundation / 基础建设
# GitHub Actions workflow snippet
- name: Build Nacos Server
run: mvn clean package -DskipTests
- name: Start Nacos Server
run: |
cd distribution/target/nacos-server-*/nacos
sh bin/startup.sh -m standalone
# Wait for server ready
until curl -s http://localhost:8848/nacos/v1/ns/operator/metrics; do sleep 5; done
// Example test structure
public class ConfigOpenAPIIT {
private static final String NACOS_SERVER = "http://localhost:8848";
@Test
public void testPublishConfig() {
// Pure HTTP client calls to Nacos OpenAPI
// No Spring context involved
}
}
Phase 2: Test Coverage Expansion / 测试覆盖扩展
EN: Gradually migrate existing IT tests to the new framework:
- OpenAPI Tests - Configuration, Naming, Authority APIs
- AdminAPI Tests - Administrative operations
- ConsoleAPI Tests - Console-specific endpoints
CN: 逐步迁移现有 IT 测试到新框架:
- OpenAPI 测试 - 配置、命名、权限相关 API
- AdminAPI 测试 - 管理操作相关
- ConsoleAPI 测试 - 控制台专用接口
Phase 3: Cleanup / 清理阶段
EN: Remove legacy components:
- Old IT configurations in
test/ directory
- Deprecated test classes
- Internal dependencies like
Nacos.java in console module
CN: 移除遗留组件:
test/ 目录下的旧 IT 配置
- 废弃的测试类
- console 模块下的
Nacos.java 等内部依赖
📋 TODO List / 任务清单
🔍 Key Discussion Points / 核心讨论方向
-
EN: Should we support external database (MySQL) testing in addition to Derby? / 是否需要支持除 Derby 外的外部数据库(如 MySQL)测试?
-
EN: How to handle test data isolation between different test classes? / 如何处理不同测试类之间的测试数据隔离?
-
EN: Should we provide a test utility library for common operations (setup, teardown, HTTP clients)? / 是否需要提供测试工具库来封装常用操作(初始化、清理、HTTP 客户端)?
-
EN: What's the rollback strategy if the new framework encounters issues? / 如果新框架遇到问题,回滚策略是什么?
🤝 Call for Discussion & Contribution / 社区讨论与贡献方向
EN: This is a significant refactoring effort that will improve the reliability and performance of Nacos integration tests. Community input is welcome on:
- Technical approach and implementation details
- Prioritization of test migration
- Best practices for test data management
CN: 这是一次重要的重构工作,将提升 Nacos 集成测试的可靠性和性能。欢迎社区就以下方面提供意见:
- 技术方案和实现细节
- 测试迁移的优先级
- 测试数据管理的最佳实践
Related: #14877
🌐 Background / 背景
The current IT implementation can be found at: https://github.com/alibaba/nacos/tree/develop/test
📦 Current State / 当前进展
Proof of Concept: A sample
ConfigOpenAPIIT test class has been implemented to demonstrate the viability of this approach.🎯 Migration Strategy / 迁移策略
🛠 Technical Proposal / 技术方案规划
Phase 1: Foundation / 基础建设
Phase 2: Test Coverage Expansion / 测试覆盖扩展
Phase 3: Cleanup / 清理阶段
📋 TODO List / 任务清单
consolemoduleNacos.java) / 移除旧测试依赖的内部代码🔍 Key Discussion Points / 核心讨论方向
EN: Should we support external database (MySQL) testing in addition to Derby? / 是否需要支持除 Derby 外的外部数据库(如 MySQL)测试?
EN: How to handle test data isolation between different test classes? / 如何处理不同测试类之间的测试数据隔离?
EN: Should we provide a test utility library for common operations (setup, teardown, HTTP clients)? / 是否需要提供测试工具库来封装常用操作(初始化、清理、HTTP 客户端)?
EN: What's the rollback strategy if the new framework encounters issues? / 如果新框架遇到问题,回滚策略是什么?
🤝 Call for Discussion & Contribution / 社区讨论与贡献方向
Related: #14877