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

Fixed docker testing #2328

Merged
merged 10 commits into from
Jun 21, 2024
Merged

Fixed docker testing #2328

merged 10 commits into from
Jun 21, 2024

Conversation

cmnrd
Copy link
Collaborator

@cmnrd cmnrd commented Jun 20, 2024

For some reason, we were not testing the docker generation using the launch scripts that we place in bin, but instead the test framework would generate a custom docker compose file and run that. This, however, did not work at all. I don't understand the precise reasons, but for the docker tests it would simply do nothing. Thus, a couple of problems in the docker generation were masked, as we never really executed the containers or tested the generated launch script.

This PR simply removes the generation of custom docker compose files in the test framework and executes the tests using the generated launch script. This PR also includes a series of fixes for bugs that were uncovered by this change.

Summary by CodeRabbit

  • New Features

    • Added Docker support across multiple components for enhanced containerization capabilities.
    • Introduced a Docker parameter in the TypeScript file configuration, which can be set dynamically.
  • Refactor

    • Refined file path handling and command creation to improve script generation and Docker integration.
    • Simplified Docker-related functionality in test setups.
  • Bug Fixes

    • Adjusted method and command logic to ensure compatibility with Docker environments.

These changes collectively improve Docker support, streamline file path handling, and refine script generation logic.

@cmnrd cmnrd added docker Issue related to the docker support exclude Exclude from change log labels Jun 20, 2024
Copy link

coderabbitai bot commented Jun 20, 2024

Walkthrough

The recent updates enhance Docker support across multiple components of the project. These changes include method additions, path resolution adjustments, and Docker integration in test configurations and TypeScript file generation. Key modifications ensure Docker compatibility, streamline Docker-related command executions, and introduce new Docker handling in TypeScript configuration.

Changes

Files Change Summary
core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java Added supportsDockerOption() method to enable Docker support.
core/src/main/.../lf/lang/generator/docker/DockerComposeGenerator.java Modified createLauncher() for path resolution using Unix string manipulation.
core/src/main/.../generator/cpp/CppPlatformGenerator.kt Introduced toUnixString import and adjusted path conversion with relativeBinDir.
core/src/main/.../generator/cpp/CppRos2Generator.kt Improved file path resolutions, Docker image generation, and colcon command creation.
core/src/main/.../generator/cpp/CppStandaloneGenerator.kt Refined handling of CMake install bindir path, added relativeBinDir, and updated executable generation methods.
core/src/testFixtures/.../org/lflang/tests/TestBase.java Streamlined Docker-related test setup, removed DOCKER_RUN_SCRIPT, simplified execution commands.
core/src/main/.../generator/ts/TSFileConfig.kt Added docker parameter in the constructor, introduced setDocker() method, and updated command execution logic to handle Docker.
core/src/main/.../generator/ts/TSGenerator.kt Set Docker property in fileConfig.
core/src/main/java/org/lflang/generator/LFGenerator.java Added extra argument to TSFileConfig constructor for TypeScript to include Docker parameter.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CppTest
    participant DockerComposeGenerator
    participant LFGenerator
    participant TSFileConfig
    participant TestBase

    User->>CppTest: Request for Docker support
    CppTest-->>CppTest: Executes supportsDockerOption()

    User->>DockerComposeGenerator: Create launcher with Unix paths
    DockerComposeGenerator->>DockerComposeGenerator: Use FileUtil.toUnixString() and relativize()

    User->>LFGenerator: Generate file config for TypeScript
    LFGenerator->>TSFileConfig: Pass Docker parameter to constructor

    User->>TSFileConfig: Set Docker property
    TSFileConfig->>TSFileConfig: Use setDocker() method
    TSFileConfig-->>User: Provide command using Docker

    User->>TestBase: Execute Docker-related tests
    TestBase-->>TestBase: Simplify Docker command determination, remove DOCKER_RUN_SCRIPT
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ff32521 and 90e6828.

Files selected for processing (6)
  • core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java (1 hunks)
  • core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java (1 hunks)
  • core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt (2 hunks)
  • core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt (4 hunks)
  • core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt (3 hunks)
  • core/src/testFixtures/java/org/lflang/tests/TestBase.java (3 hunks)
Additional comments not posted (10)
core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt (2)

14-14: Added import for org.lflang.toUnixString. Ensure it is used appropriately in the file.


28-28: Initialization of relativeBinDir with Unix-style path ensures consistency across environments. Verify that all uses of relativeBinDir are consistent with this expectation.

Verification successful

The initialization of relativeBinDir with a Unix-style path is consistent with its usage across the codebase. All references to relativeBinDir in CppRos2Generator.kt and CppStandaloneGenerator.kt align with the expectation of Unix-style paths, ensuring consistency across different environments.

  • core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt
  • core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all usages of `relativeBinDir` to ensure consistency.

# Test: Search for `relativeBinDir` usage. Expect: Consistent usage across the file.
rg --type kotlin $'relativeBinDir' core/src/main/kotlin/org/lflang/generator/cpp/CppPlatformGenerator.kt

Length of output: 203



Script:

#!/bin/bash
# Description: Verify all usages of `relativeBinDir` to ensure consistency.

# Test: Search for `relativeBinDir` usage across the entire codebase.
rg --type kotlin 'relativeBinDir'

Length of output: 1127

core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java (1)

52-55: Addition of supportsDockerOption method correctly indicates Docker support for C++ tests. This is a crucial update given the PR's focus on Docker testing.

core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt (3)

61-61: Modification of the colcon command generation to dynamically include arguments is a flexible approach, accommodating various build configurations.


94-100: The updated Docker entry point and executable copying logic are well-defined, ensuring that the Docker container is correctly set up with the necessary executables.


42-42: The conditional path resolution based on Docker settings is a robust approach to handle different environments. Ensure the paths are correctly computed in all scenarios.

Verification successful

To ensure the paths are correctly computed in both Docker and non-Docker environments, we need to investigate the context around the two occurrences of fileConfig.srcGenPath.resolve in CppRos2Generator.kt. Specifically, we should look for any conditions or configurations that handle Docker settings.


The context provided confirms that the path resolution in CppRos2Generator.kt is correctly conditional based on Docker settings. Specifically, the scriptPath is resolved differently depending on whether Docker is enabled or not.

  • When Docker is enabled: fileConfig.srcGenPath.resolve(relativeBinDir).resolve(fileConfig.name)
  • When Docker is not enabled: fileConfig.binPath.resolve(fileConfig.name)

This ensures that the paths are correctly computed in both Docker and non-Docker environments.

  • core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt:
    • Line 42: fileConfig.srcGenPath.resolve(relativeBinDir).resolve(fileConfig.name)
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct computation of paths based on Docker settings.

# Test: Check if the paths resolve correctly in both Docker and non-Docker environments.
rg --type kotlin $'fileConfig.srcGenPath.resolve' core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt

Length of output: 284



Script:

#!/bin/bash
# Description: Search for Docker-related conditions or configurations in CppRos2Generator.kt.

# Test: Look for references to Docker settings in the file.
rg --type kotlin 'Docker' core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt

Length of output: 465


Script:

#!/bin/bash
# Description: Search for conditions that might differentiate Docker and non-Docker environments.

# Test: Look for if conditions or similar constructs in the file.
rg --type kotlin 'if' core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt

Length of output: 263


Script:

#!/bin/bash
# Description: Retrieve the full context of the lines where path resolution occurs.

# Test: Print the surrounding lines of the path resolution occurrences.
rg --type kotlin -A 5 -B 5 'fileConfig.srcGenPath.resolve' core/src/main/kotlin/org/lflang/generator/cpp/CppRos2Generator.kt

Length of output: 1121

core/src/main/java/org/lflang/generator/docker/DockerComposeGenerator.java (1)

132-134: The use of FileUtil.toUnixString for path conversion in createLauncher ensures Unix-style path consistency, which is crucial for Docker environments.

core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt (2)

179-179: Ensure the use of relativeBinDir aligns with the refactored path handling in the Docker context.

Verification successful

Let's start by verifying the initialization of relativeBinDir in CppPlatformGenerator.kt and then ensure its consistent usage in the Docker context within CppStandaloneGenerator.kt.


The initialization of relativeBinDir in CppPlatformGenerator.kt is consistent and aligns with the expected path handling. Additionally, the usage of relativeBinDir within CppStandaloneGenerator.kt is consistent and appears correctly integrated with the Docker context.

  • Initialization of relativeBinDir:

    • CppPlatformGenerator.kt: protected val relativeBinDir = fileConfig.outPath.relativize(fileConfig.binPath).toUnixString()
  • Usage in CppStandaloneGenerator.kt:

    • "-DCMAKE_INSTALL_BINDIR=$relativeBinDir"
    • defaultEntryPoint(): listOf("$relativeBinDir/${fileConfig.name}")
    • generateCopyOfExecutable(): COPY --from=builder /lingua-franca/$name/$relativeBinDir/$name ./$relativeBinDir/$name

No issues found with the use of relativeBinDir in the Docker context.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the variable `relativeBinDir` is properly initialized and used across the project.

# Test: Search for 'relativeBinDir' usage. Expect: Consistent initialization and usage.
rg --type kotlin 'relativeBinDir'

Length of output: 1127



Script:

#!/bin/bash
# Verify the initialization of `relativeBinDir` in `CppPlatformGenerator.kt`
ast-grep --lang kotlin --pattern 'protected val relativeBinDir = $_' --json

# Ensure consistent usage in Docker context in `CppStandaloneGenerator.kt`
rg --context 5 'relativeBinDir' core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt

# Confirm Docker-related path handling is correct
rg 'Docker' core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneGenerator.kt

Length of output: 2193


Line range hint 195-222: Refactored Docker generator looks clean and well-structured. Ensure that the new Docker commands align with the project's Docker strategy.

core/src/testFixtures/java/org/lflang/tests/TestBase.java (1)

573-577: Refactoring of the getExecCommand method to use LFCommand looks appropriate. Ensure that the command generation and execution are thoroughly tested since they are critical for test reliability.

Verification successful

The search results indicate that there are numerous test methods annotated with @Test in the subclasses of TestBase within the core/src/integrationTest/java/org/lflang/tests/runtime directory. This suggests that the getExecCommand method is indirectly tested through these subclasses.

  • core/src/integrationTest/java/org/lflang/tests/runtime/CppTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/TypeScriptTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/RustTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/CppRos2Test.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/CZephyrTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/PythonTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/CVerifierTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/CSchedulerTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/CFlexPRETTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/CTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/CCppTest.java
  • core/src/integrationTest/java/org/lflang/tests/runtime/CArduinoTest.java

Given this extensive coverage, it is reasonable to conclude that the getExecCommand method is adequately tested through these integration tests.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct functionality of `getExecCommand` method in different scenarios.

# Test: Search for `getExecCommand` usage in tests. Expect: Proper handling and execution.
rg --type java 'getExecCommand'

Length of output: 260



Script:

#!/bin/bash
# Search for all public methods in TestBase.java and check if they call getExecCommand.
ast-grep --lang java --pattern 'public $_ $_($_) { $$$ }' core/src/testFixtures/java/org/lflang/tests/TestBase.java

Length of output: 2055



Script:

#!/bin/bash
# Search for instances where TestBase is used in test files.
rg --type java 'TestBase'

Length of output: 5510



Script:

#!/bin/bash
# Search for test methods in the subclasses of TestBase.
rg --type java '@Test' core/src/integrationTest/java/org/lflang/tests/runtime

Length of output: 3843

@cmnrd
Copy link
Collaborator Author

cmnrd commented Jun 20, 2024

Turns out that the TypeScript docker test is failing. I don't understand why, though. It works fine if I compile it with lfc, even if I manually force useHierarchicalBin=true. @petervdonovan is that something you could help with?

@cmnrd cmnrd added this to the 0.8.0 milestone Jun 20, 2024
Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

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

This looks like some serious cruft in the testing framework you got rid of. I wasn't even aware that it was there...

@petervdonovan
Copy link
Collaborator

This, however, did not work at all. I don't understand the precise reasons, but for the docker tests it would simply do nothing.

I'm not sure I understand because it seems to me like the tests have been doing something. For example, this comment that you posted earlier @cmnrd shows a runtime error (during dynamic linking) while executing a Docker test with docker compose, presumably via the Bash script that was in the test framework.

Copy link
Collaborator

@petervdonovan petervdonovan left a comment

Choose a reason for hiding this comment

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

With the changes in this PR, test/C/src/docker/FilesPropertyContainerized does not result in a test failure even when it finishes with a nonzero exit code. You can verify this by adding exit(1) to the startup reaction and running the C Docker tests:

target C {
  files: "../include/hello.h",
  docker: true
}

preamble {=
  #include "hello.h"
=}

main reactor {
  reaction(startup) {=
    hello_t hello;
    exit(1);
    printf("SUCCESS\n");
  =}
}

But in master, this modified version of the test fails with a helpful error message, as it should:

====================================================================
ERROR: One or multiple containers exited with a non-zero exit code.
       See the log above for details. The following containers failed:
FilesPropertyContainerized exited with code 1

+---------------------------------------------------------------------------+

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 90e6828 and d4cb99b.

Files selected for processing (2)
  • core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt (2 hunks)
  • core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt (1 hunks)
Additional comments not posted (4)
core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt (3)

45-45: Added a new optional parameter docker to the constructor to manage Docker support.

This change aligns with the PR's objective to enhance Docker support in the TypeScript generation. Ensure that all instances of TSFileConfig are updated to handle the new constructor signature where used.


57-59: Introduced setDocker method to dynamically enable or disable Docker support.

This method provides flexibility in configuring Docker support at runtime, which is crucial for conditional Docker usage based on environment or other settings.


62-73: Refactored getCommand to handle Docker mode dynamically.

This refactor enhances the command generation logic to accommodate Docker-based execution paths, which is essential for the Docker integration. The exception handling for undefined Docker mode is a good safety measure.

core/src/main/kotlin/org/lflang/generator/ts/TSGenerator.kt (1)

115-115: Enhanced the doGenerate method to set Docker support based on configuration.

This line ensures that Docker settings are properly configured before proceeding with generation, which is critical for maintaining consistent behavior in Docker environments.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d4cb99b and c00b057.

Files selected for processing (1)
  • core/src/main/java/org/lflang/generator/LFGenerator.java (1 hunks)

core/src/main/java/org/lflang/generator/LFGenerator.java Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c00b057 and 7ce0fea.

Files selected for processing (1)
  • core/src/main/java/org/lflang/generator/LFGenerator.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/src/main/java/org/lflang/generator/LFGenerator.java

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7ce0fea and cf6c1f3.

Files selected for processing (1)
  • core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7ce0fea and cf6c1f3.

Files selected for processing (1)
  • core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • core/src/main/kotlin/org/lflang/generator/ts/TSFileConfig.kt

Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

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

🚀

@lhstrh lhstrh removed the exclude Exclude from change log label Jun 21, 2024
@lhstrh lhstrh added the testing label Jun 21, 2024
@lhstrh lhstrh enabled auto-merge June 21, 2024 05:43
@lhstrh lhstrh dismissed petervdonovan’s stale review June 21, 2024 05:44

Pretty sure this has been addressed

@lhstrh lhstrh added this pull request to the merge queue Jun 21, 2024
Merged via the queue into master with commit 66d7d59 Jun 21, 2024
26 checks passed
@lhstrh lhstrh deleted the fix-docker-test branch June 21, 2024 06:35
@cmnrd
Copy link
Collaborator Author

cmnrd commented Jun 21, 2024

I'm not sure I understand because it seems to me like the tests have been doing something. For example, this comment that you posted earlier @cmnrd shows a runtime error (during dynamic linking) while executing a Docker test with docker compose, presumably via the Bash script that was in the test framework.

I don't fully understand either. It appears that our tests were good at picking up errors where our generated binary fails, but not where the container execution itself fails. The error message that you link to did not show up in testing, but only when I executed the program myself. Similarly, I was struggling with an issue where the entry point in the dockerfile was wrong, but it did not show up in the tests (The output from the execute step was simply empty).

With the changes in this PR, test/C/src/docker/FilesPropertyContainerized does not result in a test failure even when it finishes with a nonzero exit code. You can verify this by adding exit(1) to the startup reaction and running the C Docker tests:

That is an excellent catch! I did not notice that docker compose up would mask those errors. I addressed this in #2330

Pretty sure this has been addressed

Nope...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docker Issue related to the docker support testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants