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

Side by Side Diff: pkg/analyzer/test/src/dart/analysis/mutex_test.dart

Issue 3006563003: Implement Mutex for Dart. (Closed)
Patch Set: Created 3 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
Brian Wilkerson 2017/08/25 16:56:44 2017
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.
4
5 import 'dart:async';
6
7 import 'package:analyzer/src/dart/analysis/mutex.dart';
8 import 'package:test/test.dart';
9 import 'package:test_reflective_loader/test_reflective_loader.dart';
10
11 main() {
12 defineReflectiveSuite(() {
13 defineReflectiveTests(MutexTest);
14 });
15 }
16
17 @reflectiveTest
18 class MutexTest {
19 test_acquire() async {
20 var values = <int>[];
21 var mutex = new Mutex();
22 await Future.wait([
23 new Future(() async {
24 await mutex.acquire();
25 try {
26 await new Future.delayed(new Duration(milliseconds: 10));
27 values.add(1);
28 } finally {
29 mutex.release();
30 }
31 }),
32 new Future(() async {
33 await mutex.acquire();
34 try {
35 values.add(2);
36 } finally {
37 mutex.release();
38 }
39 }),
40 ]);
41 // The first Future is schedule first, and it acquires the mutex first.
42 // But then it sleeps before adding (1), so if Mutex locking does not work,
43 // the second Future might add (2) first.
44 expect(values, [1, 2]);
45 }
46
47 test_release_noLock() {
48 var mutex = new Mutex();
49 expect(() {
50 mutex.release();
51 }, throwsStateError);
52 }
53
54 test_release_noLock_alreadyReleased() async {
55 var mutex = new Mutex();
56 await mutex.acquire();
57 mutex.release();
58 expect(() {
59 mutex.release();
60 }, throwsStateError);
61 }
62 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698