Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: tests/standalone/io/file_blocking_lock_test.dart

Issue 2067823002: Fix flaking file lock test (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove delay Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/file_blocking_lock_test.dart
diff --git a/tests/standalone/io/file_blocking_lock_test.dart b/tests/standalone/io/file_blocking_lock_test.dart
index ef826a2037075efa3dd2f35f13fd8db7653dff36..9cd66890dffa93a3316a4991d7bd1800413273ae 100644
--- a/tests/standalone/io/file_blocking_lock_test.dart
+++ b/tests/standalone/io/file_blocking_lock_test.dart
@@ -39,7 +39,6 @@ runPeer(String path, int len, FileLock mode) {
testLockWholeFile() async {
const int length = 25;
- asyncStart();
Directory directory = await Directory.systemTemp.createTemp('dart_file_lock');
File file = new File(join(directory.path, "file"));
await file.writeAsBytes(new List.filled(length, 0));
@@ -48,10 +47,6 @@ testLockWholeFile() async {
await raf.lock(FileLock.BLOCKING_EXCLUSIVE, 0, length);
Process peer = await runPeer(file.path, length, FileLock.BLOCKING_EXCLUSIVE);
- // Wait a bit for the other process to get started. We'll synchronize on
- // the file lock.
- await new Future.delayed(const Duration(seconds: 1));
-
int nextToWrite = 1;
int at = 0;
List iWrote = new List.filled(length, 0);
@@ -64,13 +59,17 @@ testLockWholeFile() async {
// other process was able to take the lock and write some bytes.
iWrote[nextToWrite-1] = nextToWrite;
nextToWrite++;
- await raf.unlock(0, length);
- try {
- await raf.lock(FileLock.EXCLUSIVE, 0, length);
- } catch(e) {
- // Check that at some point the non-blocking lock fails.
- nonBlockingFailed = true;
- await raf.lock(FileLock.BLOCKING_EXCLUSIVE, 0, length);
+ // Let the other process get the lock at least once by spinning until the
+ // non-blocking lock fails.
+ while (!nonBlockingFailed) {
+ await raf.unlock(0, length);
+ try {
+ await raf.lock(FileLock.EXCLUSIVE, 0, length);
+ } catch(e) {
+ // Check that at some point the non-blocking lock fails.
+ nonBlockingFailed = true;
+ await raf.lock(FileLock.BLOCKING_EXCLUSIVE, 0, length);
+ }
}
while (true) {
p = await raf.position();
@@ -96,14 +95,15 @@ testLockWholeFile() async {
Expect.equals(true, nonBlockingFailed);
- peer.exitCode.then((v) {
+ await peer.exitCode.then((v) async {
Expect.equals(0, v);
- raf.closeSync();
- directory.deleteSync(recursive: true);
- asyncEnd();
+ await raf.close();
+ await directory.delete(recursive: true);
});
}
-main() {
- testLockWholeFile();
+main() async {
+ asyncStart();
+ await testLockWholeFile();
+ asyncEnd();
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698