Skip to content

Commit

Permalink
Extended container startup timeouts from 60 and 90 seconds to 150 sec…
Browse files Browse the repository at this point in the history
…onds.

Refactored WaitStrategies to read timeout value from one place, to facilitate easy tweaking of this value. There is, I think, little value of having different timeouts for different tests.
  • Loading branch information
neo-tobias committed Sep 17, 2024
1 parent 646659e commit de15b5f
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 32 deletions.
4 changes: 2 additions & 2 deletions src/test/java/com/neo4j/docker/TestDeprecationWarning.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void shouldWarnIfUsingDeprecatedBaseOS_coreDB() throws Exception
container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ))
.waitingFor( WaitStrategies.waitForBoltReady( Duration.ofSeconds( 90 ) ) );
.waitingFor( WaitStrategies.waitForBoltReady() );
container.start();
// container should successfully start
String logs = container.getLogs( OutputFrame.OutputType.STDERR );
Expand Down Expand Up @@ -92,7 +92,7 @@ void shouldIgnoreDeprecationSuppression_coreDB() throws Exception
.withEnv( DEPRECATION_WARN_SUPPRESS_FLAG, "suppress" )
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ))
.waitingFor( WaitStrategies.waitForBoltReady( Duration.ofSeconds( 90 ) ) );
.waitingFor( WaitStrategies.waitForBoltReady() );
container.start();
// container should successfully start
String logs = container.getLogs( OutputFrame.OutputType.STDERR );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private DockerComposeContainer createContainer( File composeFile, Path container
.withExposedService( serviceName, DEFAULT_HTTP_PORT )
.withEnv( "NEO4J_IMAGE", TestSettings.IMAGE_ID.asCanonicalNameString() )
.withEnv( "HOST_ROOT", containerRootDir.toAbsolutePath().toString() )
.waitingFor( serviceName, waitForBoltReady( Duration.ofSeconds( 90 ) ) )
.waitingFor( serviceName, waitForBoltReady() )
.withLogConsumer( serviceName, new Slf4jLogConsumer( log ) );

return container;
Expand Down
8 changes: 3 additions & 5 deletions src/test/java/com/neo4j/docker/coredb/TestAuthentication.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private GenericContainer createContainer( boolean asCurrentUser )
container.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor(WaitStrategies.waitForBoltReady( Duration.ofSeconds( 90) ));
.waitingFor(WaitStrategies.waitForBoltReady());
if(asCurrentUser)
{
SetContainerUser.nonRootUser( container );
Expand Down Expand Up @@ -100,9 +100,7 @@ void testDefaultPasswordAndPasswordResetIfNoNeo4jAuthSet()
try(GenericContainer container = createContainer( true ))
{
log.info( "Starting first container as current user and not specifying NEO4J_AUTH" );
container.waitingFor( WaitStrategies.waitForNeo4jReady( "neo4j",
"neo4j",
Duration.ofSeconds( 90)) );
container.waitingFor( WaitStrategies.waitForNeo4jReady( "neo4j" ) );
container.start();
DatabaseIO db = new DatabaseIO(container);
// try with no password, this should fail because the default password should be applied with no NEO4J_AUTH env variable
Expand Down Expand Up @@ -272,7 +270,7 @@ void testPromptsForPasswordReset()
String intialPass = "apassword";
String resetPass = "new_password";
container.withEnv("NEO4J_AUTH", user+"/"+intialPass+"/true" )
.waitingFor( WaitStrategies.waitForNeo4jReady( user, intialPass, Duration.ofSeconds(60)) );
.waitingFor( WaitStrategies.waitForNeo4jReady( intialPass ) );
container.start();
DatabaseIO db = new DatabaseIO(container);
Assertions.assertThrows( org.neo4j.driver.exceptions.ClientException.class,
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/neo4j/docker/coredb/TestBasic.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ void testContainerCanBeRestartedAfterUnexpectedTermination() throws IOException
int boltHostPort = getUniqueHostPort();
int browserHostPort = getUniqueHostPort();

container.waitingFor( waitForBoltReady( Duration.ofSeconds( 90 ) ) );
container.waitingFor( waitForBoltReady() );
container.withEnv( "NEO4J_AUTH", "none" );

// Ensuring host ports are constant with container restarts
Expand All @@ -262,7 +262,7 @@ void testContainerCanBeRestartedAfterUnexpectedTermination() throws IOException
container.getDockerClient().startContainerCmd( container.getContainerId() ).exec();

// Applying the Waiting strategy to ensure container is correctly running, because DockerClient does not check
waitForBoltReady( Duration.ofSeconds( 90 ) ).waitUntilReady( container );
waitForBoltReady().waitUntilReady( container );
}
}

Expand All @@ -276,7 +276,7 @@ void testExtensionScriptIsExecuted() throws IOException
try ( GenericContainer container = createBasicContainer() )
{
temporaryFolderManager.mountHostFolderAsVolume(container, scriptFolder, "/extension");
container.waitingFor(waitForBoltReady(Duration.ofSeconds(60)))
container.waitingFor(waitForBoltReady())
.withEnv("EXTENSION_SCRIPT", "/extension/startscript.sh");
container.start();
String logs = container.getLogs(OutputFrame.OutputType.STDOUT);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/neo4j/docker/coredb/TestSSL.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private GenericContainer createContainer()
.withEnv("NEO4J_DEBUG", "yes")
.withExposedPorts(7474, 7687)
.withLogConsumer(new Slf4jLogConsumer(log))
.waitingFor(WaitStrategies.waitForNeo4jReady(PASSWORD, Duration.ofSeconds(60)));
.waitingFor(WaitStrategies.waitForNeo4jReady(PASSWORD ));
return container;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void testIgnoreNumericVars()
try(GenericContainer container = createContainer())
{
container.withEnv( "NEO4J_1a", "1" )
.waitingFor( WaitStrategies.waitForBoltReady( Duration.ofSeconds( 90 ) ) );
.waitingFor( WaitStrategies.waitForBoltReady() );
container.start();
Assertions.assertTrue( container.isRunning() );
String errorLogs = container.getLogs( OutputFrame.OutputType.STDERR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected GenericContainer createContainer(String password)
.withEnv( "EXTENDED_CONF", "true" )
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor( WaitStrategies.waitForBoltReady( Duration.ofSeconds(90)));
.waitingFor( WaitStrategies.waitForBoltReady());
return container;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private GenericContainer createContainer()
.withEnv("NEO4J_DEBUG", "yes")
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor( WaitStrategies.waitForBoltReady(Duration.ofSeconds(60)) );
.waitingFor( WaitStrategies.waitForBoltReady() );
return container;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private GenericContainer createContainerWithTestingPlugin()
.withEnv( Neo4jPluginEnv.get(), "[\"_testing\"]" )
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor( WaitStrategies.waitForNeo4jReady( DB_USER, DB_PASSWORD, Duration.ofSeconds( 60 )));
.waitingFor( WaitStrategies.waitForNeo4jReady( DB_PASSWORD));
SetContainerUser.nonRootUser( container );
return container;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo
.withEnv( confNames.get( Setting.BACKUP_LISTEN_ADDRESS ).envName, "0.0.0.0:6362" )
.withExposedPorts( 7474, 7687, 6362 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor(WaitStrategies.waitForNeo4jReady( password, Duration.ofSeconds( 90 )));
.waitingFor(WaitStrategies.waitForNeo4jReady( password ));
if(!asDefaultUser)
{
SetContainerUser.nonRootUser( container );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo
.withEnv( confNames.get( Setting.BACKUP_LISTEN_ADDRESS ).envName, "0.0.0.0:6362" )
.withExposedPorts( 7474, 7687, 6362 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor(WaitStrategies.waitForNeo4jReady( password, Duration.ofSeconds( 90 )));
.waitingFor(WaitStrategies.waitForNeo4jReady( password ));
if(!asDefaultUser)
{
SetContainerUser.nonRootUser( container );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo
.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor( WaitStrategies.waitForNeo4jReady( password, Duration.ofSeconds( 90 )) );
.waitingFor( WaitStrategies.waitForNeo4jReady( password) );
if(!asDefaultUser)
{
SetContainerUser.nonRootUser( container );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private GenericContainer createDBContainer( boolean asDefaultUser, String passwo
.withEnv( "NEO4J_ACCEPT_LICENSE_AGREEMENT", "yes" )
.withExposedPorts( 7474, 7687 )
.withLogConsumer( new Slf4jLogConsumer( log ) )
.waitingFor( WaitStrategies.waitForNeo4jReady( password, Duration.ofSeconds( 90 )) )
.waitingFor( WaitStrategies.waitForNeo4jReady( password ) )
// the default testcontainer framework behaviour is to just stop the process entirely,
// preventing clean shutdown. This means we can run the stop command and
// it'll send a SIGTERM to initiate neo4j shutdown. See also stopContainer method.
Expand Down
19 changes: 7 additions & 12 deletions src/test/java/com/neo4j/docker/utils/WaitStrategies.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

public class WaitStrategies
{

private final static Duration STARTUP_TIMEOUT_SECONDS = Duration.ofSeconds(150);

private WaitStrategies() {}

public static WaitStrategy waitForNeo4jReady( String username, String password, String database, Duration timeout )
Expand All @@ -28,28 +31,20 @@ public static WaitStrategy waitForNeo4jReady( String username, String password,
.withStartupTimeout(timeout);
} else
{
return waitForBoltReady( timeout );
return waitForBoltReady();
}
}

public static WaitStrategy waitForNeo4jReady( String password ) {
return waitForNeo4jReady( "neo4j", password, "neo4j", Duration.ofSeconds(60));
}

public static WaitStrategy waitForNeo4jReady( String password, Duration timeout ) {
return waitForNeo4jReady( "neo4j", password, "neo4j", timeout);
}

public static WaitStrategy waitForNeo4jReady( String user, String password, Duration timeout ) {
return waitForNeo4jReady( user, password, "neo4j", timeout);
return waitForNeo4jReady( "neo4j", password, "neo4j", STARTUP_TIMEOUT_SECONDS);
}

public static WaitStrategy waitForBoltReady( Duration timeout )
public static WaitStrategy waitForBoltReady()
{
return Wait.forHttp("/")
.forPort(7687)
.forStatusCode(200)
.withStartupTimeout(timeout);
.withStartupTimeout(STARTUP_TIMEOUT_SECONDS);
}

/**For containers that will just run a command and exit automatically.
Expand Down

0 comments on commit de15b5f

Please sign in to comment.