diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 22e7321615..1e7e7ae518 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -35,7 +35,13 @@ jobs: --health-retries 5 ports: - 6379:6379 - + mongo: + image: mongo + env: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: root + ports: + - 27017:27017 steps: - name: Start Mysql run: sudo /etc/init.d/mysql start diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index fba7b164cb..37f67060e6 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -197,6 +197,14 @@ jobs: name: CosId Mongo Test needs: [ cosid-core-test ] runs-on: ubuntu-latest + services: + mongo: + image: mongo + env: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: root + ports: + - 27017:27017 steps: - name: Checkout uses: actions/checkout@master @@ -283,6 +291,23 @@ jobs: name: CosId Spring Boot Starter Test needs: [ cosid-core-test ] runs-on: ubuntu-latest + services: + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 6379:6379 + mongo: + image: mongo + env: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: root + ports: + - 27017:27017 steps: - name: Start Mysql run: sudo /etc/init.d/mysql start diff --git a/cosid-mongo/build.gradle.kts b/cosid-mongo/build.gradle.kts index b5fe999e73..e6445ddc48 100644 --- a/cosid-mongo/build.gradle.kts +++ b/cosid-mongo/build.gradle.kts @@ -26,3 +26,10 @@ dependencies { testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:mongodb") } + +val isInCI = null != System.getenv("CI") +if (isInCI) { + tasks.withType { + exclude("me.ahoo.cosid.mongo.MongoReactiveMachineIdDistributorTest") + } +} \ No newline at end of file diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java b/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java index 1f114b2fc5..78bd3721a0 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java @@ -18,6 +18,7 @@ import me.ahoo.cosid.converter.PrefixIdConverter; import me.ahoo.cosid.converter.Radix62IdConverter; import me.ahoo.cosid.snowflake.MillisecondSnowflakeId; +import me.ahoo.cosid.uncertainty.UncertaintyIdGenerator; /** * Mock ID Generator for test. @@ -26,12 +27,13 @@ */ public class MockIdGenerator extends StringIdGeneratorDecorator { - public static final String TEST_PREFIX = "test_"; + private static final MillisecondSnowflakeId SNOWFLAKE_ID = new MillisecondSnowflakeId(1, 0); + public static final String TEST_PREFIX = "test_"; public static final IdGenerator INSTANCE = usePrefix(TEST_PREFIX); public MockIdGenerator(String prefix) { - super(new MillisecondSnowflakeId(1, 0), new PrefixIdConverter(prefix, Radix62IdConverter.INSTANCE)); + super(SNOWFLAKE_ID, new PrefixIdConverter(prefix, Radix62IdConverter.INSTANCE)); } public static IdGenerator usePrefix(String prefix) { diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java b/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java index 5d0d607386..fc8c7e3cae 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java @@ -13,24 +13,11 @@ package me.ahoo.cosid.test.container; - -import org.testcontainers.containers.MongoDBContainer; -import org.testcontainers.shaded.com.google.common.base.Strings; -import org.testcontainers.utility.DockerImageName; - public class MongoLauncher { private static final String CONNECTION_OPTIONS = "/?connectTimeoutMS=300000&maxIdleTimeMS=300000"; private static final String DEV_CONNECTION_STRING = "mongodb://root:root@localhost" + CONNECTION_OPTIONS; - private static final MongoDBContainer MONGO_CONTAINER = new MongoDBContainer(DockerImageName.parse("mongo:6.0.12")) - .withNetworkAliases("mongo") - .withReuse(true); public static String getConnectionString() { - if (Strings.isNullOrEmpty(System.getenv("CI"))) { - return DEV_CONNECTION_STRING; - } - MONGO_CONTAINER.start(); - return MONGO_CONTAINER.getConnectionString() + CONNECTION_OPTIONS; - + return DEV_CONNECTION_STRING; } } diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/DistributeSafeGuard.java b/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/DistributeSafeGuard.java index 10c764754c..74d0894fa1 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/DistributeSafeGuard.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/DistributeSafeGuard.java @@ -72,7 +72,7 @@ public void verify() { /* * 等待所有实例到达安全守护点(SafeGuardAt),即变成可回收状态. */ - LockSupport.parkNanos(this, safeGuardDuration.plusMillis(300).toNanos()); + LockSupport.parkNanos(this, safeGuardDuration.plusMillis(800).toNanos()); availableInstances = allInstances.subList(endIdx, MachineIdDistributor.totalMachineIds(moreMachineBit)); Integer[] machineIds = availableInstances