OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // OtherResources=file_lock_script.dart | 5 // OtherResources=file_lock_script.dart |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
11 import "package:expect/expect.dart"; | 11 import "package:expect/expect.dart"; |
12 import "package:path/path.dart"; | 12 import "package:path/path.dart"; |
13 | 13 |
14 // Check whether the file is locked or not. | 14 // Check whether the file is locked or not. |
15 check(String path, int start, int end, FileLock mode, {bool locked}) { | 15 check(String path, int start, int end, FileLock mode, {bool locked}) { |
16 // Client process returns either 'LOCK FAILED' or 'LOCK SUCCEEDED'. | 16 // Client process returns either 'LOCK FAILED' or 'LOCK SUCCEEDED'. |
17 var expected = locked ? 'LOCK FAILED' : 'LOCK SUCCEEDED'; | 17 var expected = locked ? 'LOCK FAILED' : 'LOCK SUCCEEDED'; |
18 var arguments = [] | 18 var arguments = [] |
19 ..addAll(Platform.executableArguments) | 19 ..addAll(Platform.executableArguments) |
20 ..add(Platform.script.resolve('file_lock_script.dart').toFilePath()) | 20 ..add(Platform.script.resolve('file_lock_script.dart').toFilePath()) |
21 ..add(path) | 21 ..add(path) |
22 ..add(mode == FileLock.EXCLUSIVE ? 'EXCLUSIVE' : 'SHARED') | 22 ..add(mode == FileLock.EXCLUSIVE ? 'EXCLUSIVE' : 'SHARED') |
23 ..add('$start') | 23 ..add('$start') |
24 ..add('$end'); | 24 ..add('$end'); |
25 return Process.run(Platform.executable, arguments) | 25 return Process |
26 .then((ProcessResult result) { | 26 .run(Platform.executable, arguments) |
27 if (result.exitCode != 0 || !result.stdout.contains(expected)) { | 27 .then((ProcessResult result) { |
28 print("Client failed, exit code ${result.exitCode}"); | 28 if (result.exitCode != 0 || !result.stdout.contains(expected)) { |
29 print(" stdout:"); | 29 print("Client failed, exit code ${result.exitCode}"); |
30 print(result.stdout); | 30 print(" stdout:"); |
31 print(" stderr:"); | 31 print(result.stdout); |
32 print(result.stderr); | 32 print(" stderr:"); |
33 print(" arguments:"); | 33 print(result.stderr); |
34 print(arguments); | 34 print(" arguments:"); |
35 Expect.fail('Client subprocess exit code: ${result.exitCode}'); | 35 print(arguments); |
36 } | 36 Expect.fail('Client subprocess exit code: ${result.exitCode}'); |
37 }); | 37 } |
| 38 }); |
38 } | 39 } |
39 | 40 |
40 checkLocked(String path, | 41 checkLocked(String path, |
41 [int start = 0, int end = -1, FileLock mode = FileLock.EXCLUSIVE]) => | 42 [int start = 0, int end = -1, FileLock mode = FileLock.EXCLUSIVE]) => |
42 check(path, start, end, mode, locked: true); | 43 check(path, start, end, mode, locked: true); |
43 | 44 |
44 checkNotLocked(String path, | 45 checkNotLocked(String path, |
45 [int start = 0, int end = -1, FileLock mode = FileLock.EXCLUSIVE]) => | 46 [int start = 0, int end = -1, FileLock mode = FileLock.EXCLUSIVE]) => |
46 check(path, start, end, mode, locked: false); | 47 check(path, start, end, mode, locked: false); |
47 | 48 |
48 void testLockWholeFile() { | 49 void testLockWholeFile() { |
49 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 50 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
50 File file = new File(join(directory.path, "file")); | 51 File file = new File(join(directory.path, "file")); |
51 file.writeAsBytesSync(new List.filled(10, 0)); | 52 file.writeAsBytesSync(new List.filled(10, 0)); |
52 var raf = file.openSync(mode: WRITE); | 53 var raf = file.openSync(mode: WRITE); |
53 raf.lockSync(); | 54 raf.lockSync(); |
54 asyncStart(); | 55 asyncStart(); |
55 checkLocked(file.path).then((_) { | 56 checkLocked(file.path).then((_) { |
56 return checkLocked(file.path, 0, 2).then((_) { | 57 return checkLocked(file.path, 0, 2).then((_) { |
57 raf.unlockSync(); | 58 raf.unlockSync(); |
58 return checkNotLocked(file.path).then((_) { | 59 return checkNotLocked(file.path).then((_) {}); |
59 }); | |
60 }); | 60 }); |
61 }).whenComplete(() { | 61 }).whenComplete(() { |
62 raf.closeSync(); | 62 raf.closeSync(); |
63 directory.deleteSync(recursive: true); | 63 directory.deleteSync(recursive: true); |
64 asyncEnd(); | 64 asyncEnd(); |
65 }); | 65 }); |
66 } | 66 } |
67 | 67 |
68 void testLockWholeFileAsync() { | 68 void testLockWholeFileAsync() { |
69 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 69 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
70 File file = new File(join(directory.path, "file")); | 70 File file = new File(join(directory.path, "file")); |
71 file.writeAsBytesSync(new List.filled(10, 0)); | 71 file.writeAsBytesSync(new List.filled(10, 0)); |
72 var raf = file.openSync(mode: WRITE); | 72 var raf = file.openSync(mode: WRITE); |
73 asyncStart(); | 73 asyncStart(); |
74 Future.forEach([ | 74 Future.forEach([ |
75 () => raf.lock(), | 75 () => raf.lock(), |
76 () => checkLocked(file.path, 0, 2), | 76 () => checkLocked(file.path, 0, 2), |
77 () => checkLocked(file.path), | 77 () => checkLocked(file.path), |
78 () => raf.unlock(), | 78 () => raf.unlock(), |
79 () => checkNotLocked(file.path), | 79 () => checkNotLocked(file.path), |
80 ], | 80 ], (f) => f()).whenComplete(() { |
81 (f) => f()).whenComplete(() { | 81 raf.closeSync(); |
82 raf.closeSync(); | 82 directory.deleteSync(recursive: true); |
83 directory.deleteSync(recursive: true); | 83 asyncEnd(); |
84 asyncEnd(); | |
85 }); | 84 }); |
86 } | 85 } |
87 | 86 |
88 void testLockRange() { | 87 void testLockRange() { |
89 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 88 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
90 File file = new File(join(directory.path, "file")); | 89 File file = new File(join(directory.path, "file")); |
91 file.writeAsBytesSync(new List.filled(10, 0)); | 90 file.writeAsBytesSync(new List.filled(10, 0)); |
92 var raf1 = file.openSync(mode: WRITE); | 91 var raf1 = file.openSync(mode: WRITE); |
93 var raf2 = file.openSync(mode: WRITE); | 92 var raf2 = file.openSync(mode: WRITE); |
94 asyncStart(); | 93 asyncStart(); |
95 var tests = [ | 94 var tests = [ |
96 () => raf1.lockSync(FileLock.EXCLUSIVE, 2, 3), | 95 () => raf1.lockSync(FileLock.EXCLUSIVE, 2, 3), |
97 () => raf2.lockSync(FileLock.EXCLUSIVE, 5, 7), | 96 () => raf2.lockSync(FileLock.EXCLUSIVE, 5, 7), |
98 () => checkNotLocked(file.path, 0, 2), | 97 () => checkNotLocked(file.path, 0, 2), |
99 () => checkLocked(file.path, 0, 3), | 98 () => checkLocked(file.path, 0, 3), |
100 () => checkNotLocked(file.path, 4, 5), | 99 () => checkNotLocked(file.path, 4, 5), |
101 () => checkLocked(file.path, 4, 6), | 100 () => checkLocked(file.path, 4, 6), |
102 () => checkLocked(file.path, 6), | 101 () => checkLocked(file.path, 6), |
103 () => checkNotLocked(file.path, 7), | 102 () => checkNotLocked(file.path, 7), |
104 () => raf1.unlockSync(2, 3), | 103 () => raf1.unlockSync(2, 3), |
105 () => checkNotLocked(file.path, 0, 5), | 104 () => checkNotLocked(file.path, 0, 5), |
106 () => checkLocked(file.path, 4, 6), | 105 () => checkLocked(file.path, 4, 6), |
107 () => checkLocked(file.path, 6), | 106 () => checkLocked(file.path, 6), |
108 () => checkNotLocked(file.path, 7), | 107 () => checkNotLocked(file.path, 7), |
109 ]; | 108 ]; |
110 // On Windows regions unlocked must match regions locked. | 109 // On Windows regions unlocked must match regions locked. |
111 if (!Platform.isWindows) { | 110 if (!Platform.isWindows) { |
112 tests.addAll([ | 111 tests.addAll([ |
113 () => raf1.unlockSync(5, 6), | 112 () => raf1.unlockSync(5, 6), |
114 () => checkNotLocked(file.path, 0, 6), | 113 () => checkNotLocked(file.path, 0, 6), |
115 () => checkLocked(file.path, 6), | 114 () => checkLocked(file.path, 6), |
116 () => checkNotLocked(file.path, 7), | 115 () => checkNotLocked(file.path, 7), |
117 () => raf2.unlockSync(6, 7), | 116 () => raf2.unlockSync(6, 7), |
118 () => checkNotLocked(file.path) | 117 () => checkNotLocked(file.path) |
119 ]); | 118 ]); |
120 } else { | 119 } else { |
121 tests.addAll([ | 120 tests |
122 () => raf2.unlockSync(5, 7), | 121 .addAll([() => raf2.unlockSync(5, 7), () => checkNotLocked(file.path)]); |
123 () => checkNotLocked(file.path) | |
124 ]); | |
125 } | 122 } |
126 Future.forEach(tests, (f) => f()).whenComplete(() { | 123 Future.forEach(tests, (f) => f()).whenComplete(() { |
127 raf1.closeSync(); | 124 raf1.closeSync(); |
128 raf2.closeSync(); | 125 raf2.closeSync(); |
129 directory.deleteSync(recursive: true); | 126 directory.deleteSync(recursive: true); |
130 asyncEnd(); | 127 asyncEnd(); |
131 }); | 128 }); |
132 } | 129 } |
133 | 130 |
134 void testLockRangeAsync() { | 131 void testLockRangeAsync() { |
135 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 132 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
136 File file = new File(join(directory.path, "file")); | 133 File file = new File(join(directory.path, "file")); |
137 file.writeAsBytesSync(new List.filled(10, 0)); | 134 file.writeAsBytesSync(new List.filled(10, 0)); |
138 var raf1 = file.openSync(mode: WRITE); | 135 var raf1 = file.openSync(mode: WRITE); |
139 var raf2 = file.openSync(mode: WRITE); | 136 var raf2 = file.openSync(mode: WRITE); |
140 asyncStart(); | 137 asyncStart(); |
141 var tests = [ | 138 var tests = [ |
142 () => raf1.lock(FileLock.EXCLUSIVE, 2, 3), | 139 () => raf1.lock(FileLock.EXCLUSIVE, 2, 3), |
143 () => raf2.lock(FileLock.EXCLUSIVE, 5, 7), | 140 () => raf2.lock(FileLock.EXCLUSIVE, 5, 7), |
144 () => checkNotLocked(file.path, 0, 2), | 141 () => checkNotLocked(file.path, 0, 2), |
145 () => checkLocked(file.path, 0, 3), | 142 () => checkLocked(file.path, 0, 3), |
146 () => checkNotLocked(file.path, 4, 5), | 143 () => checkNotLocked(file.path, 4, 5), |
147 () => checkLocked(file.path, 4, 6), | 144 () => checkLocked(file.path, 4, 6), |
148 () => checkLocked(file.path, 6), | 145 () => checkLocked(file.path, 6), |
149 () => checkNotLocked(file.path, 7), | 146 () => checkNotLocked(file.path, 7), |
150 () => raf1.unlock(2, 3), | 147 () => raf1.unlock(2, 3), |
151 () => checkNotLocked(file.path, 0, 5), | 148 () => checkNotLocked(file.path, 0, 5), |
152 () => checkLocked(file.path, 4, 6), | 149 () => checkLocked(file.path, 4, 6), |
153 () => checkLocked(file.path, 6), | 150 () => checkLocked(file.path, 6), |
154 () => checkNotLocked(file.path, 7), | 151 () => checkNotLocked(file.path, 7), |
155 ]; | 152 ]; |
156 // On Windows regions unlocked must match regions locked. | 153 // On Windows regions unlocked must match regions locked. |
157 if (!Platform.isWindows) { | 154 if (!Platform.isWindows) { |
158 tests.addAll([ | 155 tests.addAll([ |
159 () => raf1.unlock(5, 6), | 156 () => raf1.unlock(5, 6), |
160 () => checkNotLocked(file.path, 0, 6), | 157 () => checkNotLocked(file.path, 0, 6), |
161 () => checkLocked(file.path, 6), | 158 () => checkLocked(file.path, 6), |
162 () => checkNotLocked(file.path, 7), | 159 () => checkNotLocked(file.path, 7), |
163 () => raf2.unlock(6, 7), | 160 () => raf2.unlock(6, 7), |
164 () => checkNotLocked(file.path) | 161 () => checkNotLocked(file.path) |
165 ]); | 162 ]); |
166 } else { | 163 } else { |
167 tests.addAll([ | 164 tests.addAll([() => raf2.unlock(5, 7), () => checkNotLocked(file.path)]); |
168 () => raf2.unlock(5, 7), | |
169 () => checkNotLocked(file.path) | |
170 ]); | |
171 } | 165 } |
172 Future.forEach(tests, (f) => f()).whenComplete(() { | 166 Future.forEach(tests, (f) => f()).whenComplete(() { |
173 raf1.closeSync(); | 167 raf1.closeSync(); |
174 raf2.closeSync(); | 168 raf2.closeSync(); |
175 directory.deleteSync(recursive: true); | 169 directory.deleteSync(recursive: true); |
176 asyncEnd(); | 170 asyncEnd(); |
177 }); | 171 }); |
178 } | 172 } |
179 | 173 |
180 void testLockEnd() { | 174 void testLockEnd() { |
181 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 175 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
182 File file = new File(join(directory.path, "file")); | 176 File file = new File(join(directory.path, "file")); |
183 file.writeAsBytesSync(new List.filled(10, 0)); | 177 file.writeAsBytesSync(new List.filled(10, 0)); |
184 var raf = file.openSync(mode: APPEND); | 178 var raf = file.openSync(mode: APPEND); |
185 asyncStart(); | 179 asyncStart(); |
186 Future.forEach([ | 180 Future.forEach([ |
187 () => raf.lockSync(FileLock.EXCLUSIVE, 2), | 181 () => raf.lockSync(FileLock.EXCLUSIVE, 2), |
188 () => checkNotLocked(file.path, 0, 2), | 182 () => checkNotLocked(file.path, 0, 2), |
189 () => checkLocked(file.path, 0, 3), | 183 () => checkLocked(file.path, 0, 3), |
190 () => checkLocked(file.path, 9), | 184 () => checkLocked(file.path, 9), |
191 () => raf.writeFromSync(new List.filled(10, 0)), | 185 () => raf.writeFromSync(new List.filled(10, 0)), |
192 () => checkLocked(file.path, 10), | 186 () => checkLocked(file.path, 10), |
193 () => checkLocked(file.path, 19), | 187 () => checkLocked(file.path, 19), |
194 () => raf.unlockSync(2), | 188 () => raf.unlockSync(2), |
195 () => checkNotLocked(file.path) | 189 () => checkNotLocked(file.path) |
196 ], | 190 ], (f) => f()).whenComplete(() { |
197 (f) => f()).whenComplete(() { | 191 raf.closeSync(); |
198 raf.closeSync(); | 192 directory.deleteSync(recursive: true); |
199 directory.deleteSync(recursive: true); | 193 asyncEnd(); |
200 asyncEnd(); | 194 }); |
201 }); | |
202 } | 195 } |
203 | 196 |
204 void testLockEndAsync() { | 197 void testLockEndAsync() { |
205 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 198 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
206 File file = new File(join(directory.path, "file")); | 199 File file = new File(join(directory.path, "file")); |
207 file.writeAsBytesSync(new List.filled(10, 0)); | 200 file.writeAsBytesSync(new List.filled(10, 0)); |
208 var raf = file.openSync(mode: APPEND); | 201 var raf = file.openSync(mode: APPEND); |
209 asyncStart(); | 202 asyncStart(); |
210 Future.forEach([ | 203 Future.forEach([ |
211 () => raf.lock(FileLock.EXCLUSIVE, 2), | 204 () => raf.lock(FileLock.EXCLUSIVE, 2), |
212 () => checkNotLocked(file.path, 0, 2), | 205 () => checkNotLocked(file.path, 0, 2), |
213 () => checkLocked(file.path, 0, 3), | 206 () => checkLocked(file.path, 0, 3), |
214 () => checkLocked(file.path, 9), | 207 () => checkLocked(file.path, 9), |
215 () => raf.writeFromSync(new List.filled(10, 0)), | 208 () => raf.writeFromSync(new List.filled(10, 0)), |
216 () => checkLocked(file.path, 10), | 209 () => checkLocked(file.path, 10), |
217 () => checkLocked(file.path, 19), | 210 () => checkLocked(file.path, 19), |
218 () => raf.unlock(2), | 211 () => raf.unlock(2), |
219 () => checkNotLocked(file.path) | 212 () => checkNotLocked(file.path) |
220 ], | 213 ], (f) => f()).whenComplete(() { |
221 (f) => f()).whenComplete(() { | 214 raf.closeSync(); |
222 raf.closeSync(); | 215 directory.deleteSync(recursive: true); |
223 directory.deleteSync(recursive: true); | 216 asyncEnd(); |
224 asyncEnd(); | 217 }); |
225 }); | |
226 } | 218 } |
227 | 219 |
228 void testLockShared() { | 220 void testLockShared() { |
229 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 221 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
230 File file = new File(join(directory.path, "file")); | 222 File file = new File(join(directory.path, "file")); |
231 file.writeAsBytesSync(new List.filled(10, 0)); | 223 file.writeAsBytesSync(new List.filled(10, 0)); |
232 var raf = file.openSync(); | 224 var raf = file.openSync(); |
233 asyncStart(); | 225 asyncStart(); |
234 Future.forEach([ | 226 Future.forEach([ |
235 () => raf.lock(FileLock.SHARED), | 227 () => raf.lock(FileLock.SHARED), |
236 () => checkLocked(file.path), | 228 () => checkLocked(file.path), |
237 () => checkLocked(file.path, 0, 2), | 229 () => checkLocked(file.path, 0, 2), |
238 () => checkNotLocked(file.path, 0, 2, FileLock.SHARED) | 230 () => checkNotLocked(file.path, 0, 2, FileLock.SHARED) |
239 ], | 231 ], (f) => f()).then((_) { |
240 (f) => f()).then((_) { | 232 raf.closeSync(); |
241 raf.closeSync(); | 233 directory.deleteSync(recursive: true); |
242 directory.deleteSync(recursive: true); | 234 asyncEnd(); |
243 asyncEnd(); | 235 }); |
244 }); | |
245 } | 236 } |
246 | 237 |
247 void testLockSharedAsync() { | 238 void testLockSharedAsync() { |
248 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 239 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
249 File file = new File(join(directory.path, "file")); | 240 File file = new File(join(directory.path, "file")); |
250 file.writeAsBytesSync(new List.filled(10, 0)); | 241 file.writeAsBytesSync(new List.filled(10, 0)); |
251 var raf = file.openSync(); | 242 var raf = file.openSync(); |
252 asyncStart(); | 243 asyncStart(); |
253 Future.forEach([ | 244 Future.forEach([ |
254 () => raf.lock(FileLock.SHARED), | 245 () => raf.lock(FileLock.SHARED), |
255 () => checkLocked(file.path), | 246 () => checkLocked(file.path), |
256 () => checkLocked(file.path, 0, 2), | 247 () => checkLocked(file.path, 0, 2), |
257 () => checkNotLocked(file.path, 0, 2, FileLock.SHARED) | 248 () => checkNotLocked(file.path, 0, 2, FileLock.SHARED) |
258 ], | 249 ], (f) => f()).whenComplete(() { |
259 (f) => f()).whenComplete(() { | 250 raf.closeSync(); |
260 raf.closeSync(); | 251 directory.deleteSync(recursive: true); |
261 directory.deleteSync(recursive: true); | 252 asyncEnd(); |
262 asyncEnd(); | 253 }); |
263 }); | |
264 } | 254 } |
265 | 255 |
266 void testLockAfterLength() { | 256 void testLockAfterLength() { |
267 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 257 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
268 File file = new File(join(directory.path, "file")); | 258 File file = new File(join(directory.path, "file")); |
269 file.writeAsBytesSync(new List.filled(10, 0)); | 259 file.writeAsBytesSync(new List.filled(10, 0)); |
270 var raf = file.openSync(mode: APPEND); | 260 var raf = file.openSync(mode: APPEND); |
271 asyncStart(); | 261 asyncStart(); |
272 Future.forEach([ | 262 Future.forEach([ |
273 () => raf.lockSync(FileLock.EXCLUSIVE, 2, 15), | 263 () => raf.lockSync(FileLock.EXCLUSIVE, 2, 15), |
274 () => checkNotLocked(file.path, 0, 2), | 264 () => checkNotLocked(file.path, 0, 2), |
275 () => checkLocked(file.path, 0, 3), | 265 () => checkLocked(file.path, 0, 3), |
276 () => checkLocked(file.path, 9), | 266 () => checkLocked(file.path, 9), |
277 () => checkLocked(file.path, 14), | 267 () => checkLocked(file.path, 14), |
278 () => raf.writeFromSync(new List.filled(10, 0)), | 268 () => raf.writeFromSync(new List.filled(10, 0)), |
279 () => checkLocked(file.path, 10), | 269 () => checkLocked(file.path, 10), |
280 () => checkNotLocked(file.path, 15), | 270 () => checkNotLocked(file.path, 15), |
281 () => raf.unlockSync(2, 15), | 271 () => raf.unlockSync(2, 15), |
282 () => checkNotLocked(file.path) | 272 () => checkNotLocked(file.path) |
283 ], | 273 ], (f) => f()).whenComplete(() { |
284 (f) => f()).whenComplete(() { | 274 raf.closeSync(); |
285 raf.closeSync(); | 275 directory.deleteSync(recursive: true); |
286 directory.deleteSync(recursive: true); | 276 asyncEnd(); |
287 asyncEnd(); | 277 }); |
288 }); | |
289 } | 278 } |
290 | 279 |
291 void testLockAfterLengthAsync() { | 280 void testLockAfterLengthAsync() { |
292 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); | 281 Directory directory = Directory.systemTemp.createTempSync('dart_file_lock'); |
293 File file = new File(join(directory.path, "file")); | 282 File file = new File(join(directory.path, "file")); |
294 file.writeAsBytesSync(new List.filled(10, 0)); | 283 file.writeAsBytesSync(new List.filled(10, 0)); |
295 var raf = file.openSync(mode: APPEND); | 284 var raf = file.openSync(mode: APPEND); |
296 asyncStart(); | 285 asyncStart(); |
297 Future.forEach([ | 286 Future.forEach([ |
298 () => raf.lock(FileLock.EXCLUSIVE, 2, 15), | 287 () => raf.lock(FileLock.EXCLUSIVE, 2, 15), |
299 () => checkNotLocked(file.path, 0, 2), | 288 () => checkNotLocked(file.path, 0, 2), |
300 () => checkLocked(file.path, 0, 3), | 289 () => checkLocked(file.path, 0, 3), |
301 () => checkLocked(file.path, 9), | 290 () => checkLocked(file.path, 9), |
302 () => checkLocked(file.path, 14), | 291 () => checkLocked(file.path, 14), |
303 () => raf.writeFromSync(new List.filled(10, 0)), | 292 () => raf.writeFromSync(new List.filled(10, 0)), |
304 () => checkLocked(file.path, 10), | 293 () => checkLocked(file.path, 10), |
305 () => checkNotLocked(file.path, 15), | 294 () => checkNotLocked(file.path, 15), |
306 () => raf.unlock(2, 15), | 295 () => raf.unlock(2, 15), |
307 () => checkNotLocked(file.path) | 296 () => checkNotLocked(file.path) |
308 ], | 297 ], (f) => f()).whenComplete(() { |
309 (f) => f()).whenComplete(() { | 298 raf.closeSync(); |
310 raf.closeSync(); | 299 directory.deleteSync(recursive: true); |
311 directory.deleteSync(recursive: true); | 300 asyncEnd(); |
312 asyncEnd(); | 301 }); |
313 }); | |
314 } | 302 } |
315 | 303 |
316 void main() { | 304 void main() { |
317 testLockWholeFile(); | 305 testLockWholeFile(); |
318 testLockWholeFileAsync(); | 306 testLockWholeFileAsync(); |
319 testLockRange(); | 307 testLockRange(); |
320 testLockRangeAsync(); | 308 testLockRangeAsync(); |
321 testLockEnd(); | 309 testLockEnd(); |
322 testLockEndAsync(); | 310 testLockEndAsync(); |
323 testLockShared(); | 311 testLockShared(); |
324 testLockSharedAsync(); | 312 testLockSharedAsync(); |
325 testLockAfterLength(); | 313 testLockAfterLength(); |
326 testLockAfterLengthAsync(); | 314 testLockAfterLengthAsync(); |
327 } | 315 } |
OLD | NEW |