#936 closed defect (fixed)

spurious test failure due to race condition in allmydata.test.test_cli.Cp.test_copy_using_filecap

Reported by: davidsarah Owned by: warner
Priority: major Milestone: 1.6.1
Component: code-frontend-cli Version: 1.5.0
Keywords: test reviewed Cc:
Launchpad Bug:

Description

Reported by Ludovic Courtès,

http://hydra.nixos.org/build/278961/nixlog/14/raw :

allmydata.test.test_cli.Cp.test_copy_using_filecap fails with

allmydata.scripts.common.UnknownAliasError: Unknown alias 'tahoe', please create it with 'tahoe add-alias' or 'tahoe create-alias'.

I think this is because the test creates the "tahoe" alias (line 1000), but does not chain subsequent operations to the resulting Deferred. So, the alias might not have been created by the time it is needed.

Attachments (4)

fix-test-copy-using-filecap-darcspatch.txt (49.7 KB) - added by davidsarah at 2010-02-03T23:20:54Z.
Fix race condition in allmydata.test.test_cli.Cp.test_copy_using_filecap
fix-test-copy-using-filecap-diff.txt (1.1 KB) - added by davidsarah at 2010-02-03T23:25:52Z.
Same thing as a unified diff
fix-test-copy-using-filecap-2-darcspatch.txt (52.1 KB) - added by davidsarah at 2010-02-05T18:36:11Z.
Fix race conditions in allmydata.test.test_cli.Cp.test_copy_using_filecap, and minor cleanup
fix-test-cli-darcspatch.txt (63.5 KB) - added by davidsarah at 2010-02-06T01:45:58Z.
Previous attachment was missing some of my changes.

Download all attachments as: .zip

Change History (13)

Changed at 2010-02-03T23:20:54Z by davidsarah

Fix race condition in allmydata.test.test_cli.Cp.test_copy_using_filecap

Changed at 2010-02-03T23:25:52Z by davidsarah

Same thing as a unified diff

comment:1 Changed at 2010-02-03T23:48:46Z by davidsarah

  • Keywords review-needed added

comment:2 follow-up: Changed at 2010-02-05T04:07:13Z by warner

looks good. do_cli() definitely needs to be waited upon, since it uses deferToThread(). All sorts of nasty race conditions if that Deferred is ignored.

I would advise also changing the open(fn1, "wb").write(DATA1) at line 15 to explicitly close the filehandle. The file object is not obligated to flush anything until it gets GC'ed, and merely going out of scope is not enough to force that. (in practice I've never seen it behave otherwise, but that probably depends on the platform). Unfortunately the full approach is a bit verbose:

f = open(fn1, "wb")
f.write(...)
f.close()

Changed at 2010-02-05T18:36:11Z by davidsarah

Fix race conditions in allmydata.test.test_cli.Cp.test_copy_using_filecap, and minor cleanup

comment:3 Changed at 2010-02-05T20:13:05Z by davidsarah

  • Owner set to warner

Assigning to Brian for review.

Changed at 2010-02-06T01:45:58Z by davidsarah

Previous attachment was missing some of my changes.

comment:4 Changed at 2010-02-06T01:49:53Z by davidsarah

Hmm, trac seems to have deleted the description of the patch. It was:

  • fix race conditions and missing callback in allmydata.test.test_cli.Cp.test_copy_using_filecap,
  • add utilities for one-liner reading and writing of files,
  • fix cases in test_cli where files were not being closed after writing.
  • (in separate patch), refactor test_cli to use the new utilities in other places.

Note: this now opens files in binary mode where they previously opened in text mode, but I believe that's correct.

The missing callback was _copy_file in test_copy_using_filecap, which led to some of the intended checks in that test not being performed.

comment:5 in reply to: ↑ 2 Changed at 2010-02-06T01:55:50Z by davidsarah

Replying to warner:

The file object is not obligated to flush anything until it gets GC'ed, and merely going out of scope is not enough to force that. (in practice I've never seen it behave otherwise, but that probably depends on the platform).

I believe it will always behave that way in CPython (due to its use of reference counting), but not in other Python implementations.

comment:6 Changed at 2010-02-15T20:21:54Z by davidsarah

  • Milestone changed from 1.7.0 to 1.6.1

comment:7 Changed at 2010-02-21T06:00:22Z by zooko

  • Keywords reviewed added; review-needed removed

I reviewed this patch and it looks right to me. One tiny detail is that the one-liner read and write functions in the copy of fileutil in tahoe-lafs are syntactically different from those same functions in the copy of fileutil in pyutil which is too bad because it means more diffs next time I manually merge those files. (See #47 (use pyutil as a separate package and contribute src/allmydata/util/* into pyutil).)

I will apply this patch.

comment:8 Changed at 2010-02-21T06:20:31Z by zooko

fixed by c984a09fe769ba4f and 85a50feeaa0a6150. Thanks!

comment:9 Changed at 2010-02-21T06:20:38Z by zooko

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.