Opened 5 years ago

Closed 4 years ago

#8622 closed defect (fixed)

Test failing to clean up /tmp resources

Reported by: atagar Owned by: atagar
Priority: Very Low Milestone:
Component: Core Tor/Stem Version:
Severity: Keywords: testing easy
Cc: cool_asis_is@…, ashishnitinpatil@… Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description

After several test runs I noticed that we had accumulated quite a few temporary resources. This is from use of the tempfile module, at some point we're creating resources but failing to clean 'em up.

Child Tickets

Change History (10)

comment:1 Changed 5 years ago by ashishnitinpatil

Cc: cool_asis_is@… added

comment:2 Changed 5 years ago by ashishnitinpatil

In stem/runner.py line 286 - self._test_dir = tempfile.mktemp("-stem-integ")
Should it not be mkstemp rather than mktemp?
Also, would running a os.rmdir(tempfile.gettempdir()) be sufficient after being done with the tests?
Also, would not tempfile.TemporaryFile() (Deletes the temp files automatically) be a better thing to do rather than mkstemp?
Or do we need the files later for some other tests?

comment:3 Changed 5 years ago by atagar

In stem/runner.py line 286 - self._test_dir = tempfile.mktemp("-stem-integ")

Stem has a 'integ.test_directory' config option set by default so in practice no one ever hits this line (... maybe we should remove it). This is from when I first started writing stem's tests and thought that developers would always want a fresh data directory for tor. In practice it's simple enough to blow away './test/data'.

So long story short your princess is in another castle - this is not the line making the temporary resources. Have you tried running the integ tests to see what is being created in /tmp?

comment:4 Changed 5 years ago by ashishnitinpatil

No, I have not run the tests (any of them) as yet.
Still learning stuff. Will get better with time I hope.
Thanks, I'll do that & then maybe get a better look at actually
seeing the tests do their work rather skimming through the code.

comment:5 Changed 5 years ago by ashishnitinpatil

Ok, so I wrote up a few python lines at the end of main() in run_tests.py to clear up whatever is there under CONFIGinteg.test_directory?. But, for some reason, a .fuse_file is getting generated which refuses to be deleted & thus the directory can not be cleared. Any suggestions or insights?

comment:6 Changed 5 years ago by ashishnitinpatil

comment:7 Changed 5 years ago by atagar

But, for some reason, a .fuse_file is getting generated which refuses to be deleted & thus the directory can not be cleared. Any suggestions or insights?

That isn't from stem, sounds like...

https://en.wikipedia.org/wiki/FUSE_%28filesystem%29

https://pastee.org/cvnx

Good try, but that isn't the goal of this ticket. The test_directory is where we place tor's data directory and we want to keep that so subsequent test runs are faster. This ticket is about stuff being left in /tmp.

comment:8 Changed 4 years ago by ashishnitinpatil

Status: newneeds_review

Finally, got what was creating the temporary folder. Apparently, the files were automatically getting deleted but since we used mkdtemp() in runner.py (after import in run_tests.py) we have to manually delete the temp folder.
The following does the work successfully (tested on Windows & Linux) -
(I coded this into run_tests.py at about the end of main())

TEMP_DIR = os.path.dirname(test.runner.CONTROL_SOCKET_PATH)
try:
  os.rmdir(TEMP_DIR)
  println("SUCCESSFULLY CLEANED TEMP RESOURCE AT - %s"%TEMP_DIR)
except:
  println("FAILED TO CLEAN TEMP RESOURCE AT - %s"%TEMP_DIR)

comment:9 Changed 4 years ago by ashishnitinpatil

Cc: ashishnitinpatil@… added

comment:10 Changed 4 years ago by atagar

Resolution: fixed
Status: needs_reviewclosed
Note: See TracTickets for help on using tickets.