Skip to content

[Testing] Improve Functions unit tests by using unique nar extraction directory - #10032

Merged
eolivelli merged 1 commit into
apache:masterfrom
lhotari:lh-unique-nar-extraction-directory-for-tests
Mar 26, 2021
Merged

eolivelli merged 1 commit into
apache:masterfrom
lhotari:lh-unique-nar-extraction-directory-for-tests

Conversation

@lhotari

@lhotari lhotari commented Mar 24, 2021 •

Copy link
Copy Markdown
Member

Motivation

  • Existing solution used in Pulsar Functions tests doesn't support testForkCount > 1 since there is code like this in many tests:
        // delete all function temp files
        File dir = new File(System.getProperty("java.io.tmpdir"));
        File[] foundFiles = dir.listFiles((ignoredDir, name) -> name.startsWith("function"));

        for (File file : foundFiles) {
            file.delete();
        }
  • After running Pulsar tests, there are extracted nar directories left in /tmp directory. This is a sign that proper cleanup isn't happening.

Modifications

  • Create unique temporary directory for each test and use this temporary directory for WorkerConfig narExtractionDirectory, downloadDirectory and connectorDirectory settings

    • Delete the tempory directory consistently in an AfterMethod cleanup method
  • Add a feature to LocalRunner to create a unique temp directory for extracting nar files. Delete directory on close

  • Fix some ClassLoader resource cleanup issues that came up while working on the changes

  • Fix a flakiness issue that showed up in FileServer that is used in Pulsar Function Tests to serve files over http (for testing purposes).

@lhotari

lhotari commented Mar 24, 2021

Copy link
Copy Markdown
Member Author

@jerrypeng @david-streamlio please review this PR. It's a change in Pulsar Functions tests.

@lhotari

lhotari commented Mar 24, 2021

Copy link
Copy Markdown
Member Author

I noticed that there's a gap in this PR. There also needs to be handling for these temp files:

File file = Files.createTempFile("function", ".tmp").toFile();

File file = Files.createTempFile("function", ".tmp").toFile();

File file = Files.createTempFile("function", ".tmp").toFile();

@aahmed-se

Copy link
Copy Markdown
Contributor

We should be cleaning the env when the test starts not when it ends, there is no value in cleanup then.

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Awesome

Lgtm

@lhotari
lhotari force-pushed the lh-unique-nar-extraction-directory-for-tests branch from ad1846d to b7ef815 Compare March 24, 2021 12:29
@lhotari

lhotari commented Mar 24, 2021 •

Copy link
Copy Markdown
Member Author

We should be cleaning the env when the test starts not when it ends, there is no value in cleanup then.

Usually resources should be cleaned up and not left around. Isn't this the case?
@aahmed-se Please review the changes in this PR so that there's more context.

@lhotari

lhotari commented Mar 24, 2021

Copy link
Copy Markdown
Member Author

I noticed that there's a gap in this PR. There also needs to be handling for these temp files:

File file = Files.createTempFile("function", ".tmp").toFile();

File file = Files.createTempFile("function", ".tmp").toFile();

File file = Files.createTempFile("function", ".tmp").toFile();

I addressed the cleanup of these files by using the nar extraction directory as the temporary directory for these files. I think that it should be ok for that purpose. Adding yet another configuration parameter for the downloaded files would be adding too much overhead.

@lhotari

lhotari commented Mar 24, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@eolivelli

Copy link
Copy Markdown
Contributor

@aahmed-se

We cannot use the same directory and clean it up, otherwise we are not able to support concurrent tests.
Now we are using a fresh new directory, so there is no need to clean up.
It is good that we clean up in the end of the test in order to save resources (CI/localenv disk space).

@lhotari
lhotari force-pushed the lh-unique-nar-extraction-directory-for-tests branch from b7ef815 to e581b1a Compare March 24, 2021 18:39
this.secretsProviderConfig = secretsProviderConfig;
this.narExtractionDirectory = narExtractionDirectory != null ? narExtractionDirectory
: NarClassLoader.DEFAULT_NAR_EXTRACTION_DIR;
if (narExtractionDirectory != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We are changing the existing behavior here. If the narExtractionDirectory is not specified we should default to NarClassLoader.DEFAULT_NAR_EXTRACTION_DIR

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The change in behavior is intentional for LocalRunner. The intent of the changes are that unless narExtractionDirectory is specified, a temporary directory will be created which is deleted when LocalRunner.close() is called. Do you think that this type of behavior is unacceptable? I hope it would be ok to do this change since it reduces the chance that temporary files get left in the main system temp directory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it is fine

@jerrypeng jerrypeng left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally looks good. Added some come comments. Thank you for working on this.

@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

Generally looks good. Added some come comments. Thank you for working on this.

Thanks for the review @jerrypeng . I'll soon push changes to address your review comments about the deleted files check (I'll bring that back).

@lhotari
lhotari force-pushed the lh-unique-nar-extraction-directory-for-tests branch from e581b1a to 936c41b Compare March 25, 2021 06:22
@lhotari
lhotari requested a review from jerrypeng March 25, 2021 06:39
@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

@jerrypeng I have addressed the review comments. PTAL

@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

3 similar comments
@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari
lhotari force-pushed the lh-unique-nar-extraction-directory-for-tests branch from 936c41b to 943e7f4 Compare March 25, 2021 10:45
@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

1 similar comment
@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari
lhotari force-pushed the lh-unique-nar-extraction-directory-for-tests branch from 943e7f4 to 555ea60 Compare March 25, 2021 16:18
@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

1 similar comment
@lhotari

lhotari commented Mar 25, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari

lhotari commented Mar 26, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

… directory

- Use unique temporary nar extraction directory for each test
  - This fixes possible issues caused by running tests with testForkCount > 1 setting (current status in master branch)
  - Delete directory consistently in AfterMethod

- Add feature LocalRunner to create a unique temp directory for extracting
  nar files. Delete directory on close

- Fix some ClassLoader resource cleanup issues that came up while working on the changes
@lhotari
lhotari force-pushed the lh-unique-nar-extraction-directory-for-tests branch from 555ea60 to 778b72b Compare March 26, 2021 04:46
@lhotari

lhotari commented Mar 26, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

7 similar comments
@lhotari

lhotari commented Mar 26, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari

lhotari commented Mar 26, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari

lhotari commented Mar 26, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari

lhotari commented Mar 26, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari

lhotari commented Mar 26, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari

lhotari commented Mar 26, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@lhotari

lhotari commented Mar 26, 2021

Copy link
Copy Markdown
Member Author

/pulsarbot run-failure-checks

@eolivelli
eolivelli merged commit 3181689 into apache:master Mar 26, 2021
ivankelly pushed a commit to ivankelly/pulsar that referenced this pull request Aug 10, 2021
… directory (apache#10032)

- Use unique temporary nar extraction directory for each test
  - This fixes possible issues caused by running tests with testForkCount > 1 setting (current status in master branch)
  - Delete directory consistently in AfterMethod

- Add feature LocalRunner to create a unique temp directory for extracting
  nar files. Delete directory on close

- Fix some ClassLoader resource cleanup issues that came up while working on the changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants