Flutter Engine
count_down_latch_unittests.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/fml/synchronization/count_down_latch.h"
6 
7 #include <chrono>
8 #include <thread>
9 
10 #include "flutter/fml/build_config.h"
11 #include "flutter/fml/thread.h"
12 #include "flutter/testing/testing.h"
13 
14 namespace fml {
15 
16 TEST(CountDownLatchTest, CanWaitOnZero) {
17  CountDownLatch latch(0);
18  latch.Wait();
19 }
20 
21 #if OS_FUCHSIA
22 #define CanWait DISABLED_CanWait
23 #else
24 #define CanWait CanWait
25 #endif
26 TEST(CountDownLatchTest, CanWait) {
27  fml::Thread thread("test_thread");
28  const size_t count = 100;
29  size_t current_count = 0;
30  CountDownLatch latch(count);
31  auto decrement_latch_on_thread = [runner = thread.GetTaskRunner(), &latch,
32  &current_count]() {
33  runner->PostTask([&latch, &current_count]() {
34  std::this_thread::sleep_for(std::chrono::microseconds(100));
35  current_count++;
36  latch.CountDown();
37  });
38  };
39  for (size_t i = 0; i < count; ++i) {
40  decrement_latch_on_thread();
41  }
42  latch.Wait();
43  ASSERT_EQ(current_count, count);
44 }
45 
46 } // namespace fml
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: thread.cc:45
#define CanWait
Definition: ascii_trie.cc:9
TEST(MessageTest, CanEncodeTriviallyCopyableTypes)