Skip to content

Commit

Permalink
fix: CI test. (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Nov 25, 2023
1 parent fc1d7be commit 4a52658
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class MongoLauncher {
private static final String DEV_CONNECTION_STRING = "mongodb://root:root@localhost";
private static final MongoDBContainer MONGO_CONTAINER = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10"))
private static final MongoDBContainer MONGO_CONTAINER = new MongoDBContainer(DockerImageName.parse("mongo:5.0.8"))
.withNetworkAliases("mongo")
.withReuse(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,5 @@ void setup() {
protected MachineIdDistributor getDistributor() {
return machineIdDistributor;
}

@Override
protected Duration getSafeGuardDuration() {
if (System.getenv().containsKey("CI")) {
return Duration.ofSeconds(10);
}
return super.getSafeGuardDuration();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MongoReactiveMachineIdDistributorTest extends MachineIdDistributorSpec {

@BeforeEach
void setup() {
mongoDatabase = MongoClients.create(MongoLauncher.getConnectionString()).getDatabase("cosid_db");
mongoDatabase = MongoClients.create(MongoLauncher.getConnectionString()).getDatabase("cosid_db_reactive");
machineInitializer = new MongoReactiveMachineInitializer(mongoDatabase);
machineInitializer.ensureMachineCollection();
machineIdDistributor = new MongoMachineIdDistributor(
Expand All @@ -46,12 +46,5 @@ void setup() {
protected MachineIdDistributor getDistributor() {
return machineIdDistributor;
}

@Override
protected Duration getSafeGuardDuration() {
if (System.getenv().containsKey("CI")) {
return Duration.ofSeconds(10);
}
return super.getSafeGuardDuration();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void verify() {
/*
* 等待所有实例到达安全守护点(SafeGuardAt),即变成可回收状态.
*/
LockSupport.parkNanos(this, safeGuardDuration.plusMillis(10).toNanos());
LockSupport.parkNanos(this, safeGuardDuration.plusMillis(300).toNanos());
availableInstances = allInstances.subList(endIdx, MachineIdDistributor.totalMachineIds(moreMachineBit));

Integer[] machineIds = availableInstances
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import me.ahoo.cosid.test.MockIdGenerator;
import me.ahoo.cosid.test.TestSpec;

import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Supplier;

/**
Expand All @@ -42,7 +43,8 @@ public Guard(Supplier<MachineIdDistributor> implFactory, int machineBit) {
public void verify() {
MachineIdDistributor distributor = implFactory.get();
String namespace = MockIdGenerator.usePrefix("Guard").generateAsString();
InstanceId instanceId = mockInstance(0, false);
int port = ThreadLocalRandom.current().nextInt(0, 65535);
InstanceId instanceId = mockInstance(port, false);
int machineId = distributor.distribute(namespace, machineBit, instanceId, MachineIdDistributor.FOREVER_SAFE_GUARD_DURATION).getMachineId();
assertThat(machineId, equalTo(0));
distributor.guard(namespace, instanceId, MachineIdDistributor.FOREVER_SAFE_GUARD_DURATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
public abstract class MachineIdDistributorSpec {
public static final String TEST_HOST = "127.0.0.1";
private static final int TEST_MACHINE_BIT = 5;
private static final Duration TEST_SAFE_GUARD_DURATION = Duration.ofSeconds(5);
private static final Duration TEST_SAFE_GUARD_DURATION = Duration.ofSeconds(2);

protected static InstanceId mockInstance(int port, boolean stable) {
return InstanceId.of(TEST_HOST, port, stable);
Expand Down

0 comments on commit 4a52658

Please sign in to comment.