Skip to content

Commit

Permalink
Merge pull request #2821 from DataDog/glopes/fix-appsec-int-tests
Browse files Browse the repository at this point in the history
Fix appsec integration tests
  • Loading branch information
cataphract authored Aug 29, 2024
2 parents fca0ec2 + 6397d1a commit 05ae627
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions appsec/tests/integration/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ def buildRunInDockerTask = { Map options ->
volumes['php-tracer-cargo-cache'] = [
mountPoint: '/root/.cargo/registry',
]
volumes['php-tracer-cargo-cache-git'] = [
mountPoint: '/root/.cargo/git',
]
}

def composerDlTask
Expand Down Expand Up @@ -443,6 +446,7 @@ task loadCaches(type: Exec) {

dependsOn downloadCaches
dependsOn 'createVolume-php-tracer-cargo-cache'
dependsOn 'createVolume-php-tracer-cargo-cache-git'
dependsOn 'createVolume-php-appsec-hunter-cache'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.datadog.appsec.php.model.Span
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIf
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy
import org.testcontainers.containers.wait.strategy.WaitStrategy
import org.testcontainers.containers.wait.strategy.WaitStrategyTarget
import org.testcontainers.junit.jupiter.Container
Expand All @@ -23,7 +22,6 @@ import static com.datadog.appsec.php.integration.TestParams.getVariant
import static com.datadog.appsec.php.integration.TestParams.phpVersionAtLeast
import static com.datadog.appsec.php.test.JsonMatcher.matchesJson
import static java.net.http.HttpResponse.BodyHandlers.ofString
import static java.time.temporal.ChronoUnit.SECONDS
import static org.hamcrest.MatcherAssert.assertThat

@Testcontainers
Expand All @@ -45,7 +43,9 @@ class RoadRunnerTests {
phpVariant: variant,
www: 'roadrunner',
).with {
// we only start listening on http after run.sh has finished
// we only start listening on http after run.sh has finished,
// so mark immediately the container as ready. We instead check for liveliness
// in beforeAll()
setWaitStrategy(new WaitStrategy() {
@Override
void waitUntilReady(WaitStrategyTarget waitStrategyTarget) {
Expand All @@ -62,7 +62,14 @@ class RoadRunnerTests {

@BeforeAll
static void beforeAll() {
new HostPortWaitStrategy().withStartupTimeout(Duration.of(300, SECONDS) ).waitUntilReady(CONTAINER)
// wait until roadrunner is running
long deadline = System.currentTimeMillis() + 300_000
while (CONTAINER.execInContainer('grep', 'http server was started', '/tmp/logs/rr.log').exitCode != 0) {
if (System.currentTimeMillis() > deadline) {
throw new RuntimeException('Roadrunner did not start on time (see output of run.sh)')
}
Thread.sleep(500)
}
}

@Test
Expand Down

0 comments on commit 05ae627

Please sign in to comment.