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

fix: CI test. #490

Merged
merged 5 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading