Skip to content

Commit

Permalink
Fix flaky JDBC tmpfs test (#2646)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnorth committed May 2, 2020
1 parent e10c7ea commit fd28fcf
Showing 1 changed file with 4 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,43 +1,31 @@
package org.testcontainers.jdbc;

import org.junit.Rule;
import org.junit.Test;
import org.testcontainers.containers.Container;
import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.testsupport.Flaky;
import org.testcontainers.testsupport.FlakyTestJUnit4RetryRule;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;
import static org.rnorth.visibleassertions.VisibleAssertions.assertNotEquals;

public class DatabaseDriverTmpfsTest {

@Rule
public FlakyTestJUnit4RetryRule retry = new FlakyTestJUnit4RetryRule();

@Test
@Flaky(githubIssueUrl = "https://github.com/testcontainers/testcontainers-java/issues/1687", reviewDate = "2020-03-01")
public void tmpfs() throws IOException, InterruptedException, SQLException {
public void testDatabaseHasTmpFsViaConnectionString() throws Exception {
final String jdbcUrl = "jdbc:tc:postgresql:9.6.8://hostname/databasename?TC_TMPFS=/testtmpfs:rw";
try (Connection ignored = DriverManager.getConnection(jdbcUrl)) {

JdbcDatabaseContainer<?> container = ContainerDatabaseDriver.getContainer(jdbcUrl);
// check file doesn't exist
String path = "/testtmpfs/test.file";
Container.ExecResult execResult = container.execInContainer("ls", path);
assertEquals("tmpfs inside container works fine", execResult.getStderr(),
"ls: cannot access '/testtmpfs/test.file': No such file or directory\n");
assertNotEquals("tmpfs inside container doesn't have file that doesn't exist", 0, execResult.getExitCode());
// touch && check file does exist
container.execInContainer("touch", path);
execResult = container.execInContainer("ls", path);
assertEquals("tmpfs inside container works fine", execResult.getStdout(), path + "\n");
assertEquals("tmpfs inside container has file that does exist", 0, execResult.getExitCode());
}

}


}

0 comments on commit fd28fcf

Please sign in to comment.