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 unit test #996

Merged
merged 2 commits into from
Feb 21, 2024
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 @@ -121,7 +121,6 @@ public void before() throws IOException {
}

@Test
@Ignore
public void testDoTest() throws IOException {
assertThat(agentService.getAllAttachedFreeApprovedAgents().size(), is(1));
perfTestRunnable.doStart();
Expand All @@ -135,8 +134,6 @@ public void testDoTest() throws IOException {
assertThat(consoleManager.getConsoleInUse().size(), is(0));
}

private boolean ended = false;

@Test
public void testStartConsole() throws IOException {
// Get perf test
Expand Down Expand Up @@ -168,7 +165,6 @@ public void onSamplingStarted() {

@Override
public void onSamplingEnded() {
ended = true;
}

@Override
Expand Down
13 changes: 12 additions & 1 deletion ngrinder-core/src/main/java/org/ngrinder/infra/AgentConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static org.ngrinder.common.util.ExceptionUtils.processException;
import static org.ngrinder.common.util.NoOp.noOp;
import static org.ngrinder.common.util.Preconditions.checkNotNull;
import static org.ngrinder.common.util.StringUtils.defaultIfBlank;

/**
* Spring component which is responsible to get the nGrinder config which is stored
Expand Down Expand Up @@ -328,7 +329,7 @@ public void setControllerIP(String ip) {
}

public String getControllerIP() {
return defaultIfEmpty(controllerIP, NetworkUtils.getLocalHostAddress());
return defaultIfBlank(controllerIP, NetworkUtils::getLocalHostAddress);
}

public int getControllerPort() {
Expand Down Expand Up @@ -420,5 +421,15 @@ protected AgentHome resolveHome() {
}
return resolveHome;
}

@Override
public String getControllerHost() {
return "127.0.0.1";
}

@Override
public String getControllerIP() {
return "127.0.0.1";
}
}
}
25 changes: 12 additions & 13 deletions ngrinder-core/src/test/java/net/grinder/AgentControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ public void before() {
final int freePort = getFreePort();
agentControllerServerDaemon = new AgentControllerServerDaemon(freePort);
agentControllerServerDaemon.start();

agentConfig1.setControllerPort(freePort);
agentControllerDaemon = new AgentControllerDaemon(agentConfig1);

agentControllerDaemon.run();

agentConfig2.setControllerPort(freePort);
agentControllerDaemon2 = new AgentControllerDaemon(agentConfig2);
agentControllerDaemon2.run();

sleep(2000);
// Validate if all agents are well-attached.

Expand Down Expand Up @@ -172,25 +174,22 @@ public void testConsoleCommunicationSettingTimeout() throws GrinderProperties.Pe

FileUtils.copyFileToDirectory(
new File(this.getClass().getResource("/long-time-prepare-test.py").getFile()),
new File("./tmp/agent-home/tmp_1/file-store/_default/incoming")
new File("./tmp/agent-home/tmp_0/file-store/_default/incoming")
);

URL scriptUrl = this.getClass().getResource("/long-time-prepare-test.properties");
File scriptFile = new File(scriptUrl.getFile());
GrinderProperties properties = new GrinderProperties(scriptFile);
properties.setAssociatedFile(new File("long-time-prepare-test.properties"));
final MutableBoolean timeouted = new MutableBoolean(false);
console1.addListener(new SingleConsole.ConsoleShutdownListener() {
@Override
public void readyToStop(StopReason stopReason) {
// Notice: it couldn't distinguish between a script error or
// timed out of the keepalive connection.
System.out.println("The stop signal is received " + stopReason);
if (stopReason.equals(SCRIPT_ERROR)) {
timeouted.setValue(true);
}
}
});
console1.addListener(stopReason -> {
// Notice: it couldn't distinguish between a script error or
// timed out of the keepalive connection.
System.out.println("The stop signal is received " + stopReason);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about use private static final Logger LOGGER = LoggerFactory.getLogger(AgentControllerTest.class);?

if (stopReason.equals(SCRIPT_ERROR)) {
timeouted.setValue(true);
}
});
console1.startTest(properties);

for (int i = 0; i < 20; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ abstract public class AbstractMultiGrinderTestBase {

@Before
public void agentInit() {
agentConfig1 = new AgentConfig.NullAgentConfig(1);
agentConfig1 = new AgentConfig.NullAgentConfig(0);
Copy link
Contributor Author

@imbyungjun imbyungjun Jan 10, 2024

Choose a reason for hiding this comment

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

static {
System.setProperty("ngrinder.agent.home", "./tmp/agent-home");
}

I think that setting ngrinder.agent.home property as ./tmp/agent-home could derive resource contention. I wanted to fix it but no time. I'll change it if there is a next time.

agentConfig1.init();

agentConfig2 = new AgentConfig.NullAgentConfig(1);
agentConfig2.init();

agentConfig3 = new AgentConfig.NullAgentConfig(1);
agentConfig3 = new AgentConfig.NullAgentConfig(2);
agentConfig3.init();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -9,13 +9,12 @@
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* limitations under the License.
*/
package org.ngrinder.infra;


import org.apache.commons.io.FileUtils;
import org.junit.Ignore;
import org.junit.Test;

import java.io.File;
Expand All @@ -36,7 +35,6 @@ public class AgentConfigTest {
* @throws IOException
*/
@Test
@Ignore
public void testAgentConfigInitialization() throws IOException {
// Given
AgentConfig config = new AgentConfig();
Expand Down
Loading