xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/qbone/bonnet/qbone_tunnel_silo_test.cc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright (c) 2020 The Chromium 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 "quiche/quic/qbone/bonnet/qbone_tunnel_silo.h"
6 
7 #include "absl/synchronization/notification.h"
8 #include "quiche/quic/platform/api/quic_test.h"
9 #include "quiche/quic/qbone/bonnet/mock_qbone_tunnel.h"
10 
11 namespace quic {
12 namespace {
13 
14 using ::testing::Eq;
15 using ::testing::Invoke;
16 using ::testing::Return;
17 
TEST(QboneTunnelSiloTest,SiloRunsEventLoop)18 TEST(QboneTunnelSiloTest, SiloRunsEventLoop) {
19   MockQboneTunnel mock_tunnel;
20 
21   absl::Notification event_loop_run;
22   EXPECT_CALL(mock_tunnel, WaitForEvents)
23       .WillRepeatedly(Invoke([&event_loop_run]() {
24         if (!event_loop_run.HasBeenNotified()) {
25           event_loop_run.Notify();
26         }
27         return false;
28       }));
29 
30   QboneTunnelSilo silo(&mock_tunnel, false);
31   silo.Start();
32 
33   event_loop_run.WaitForNotification();
34 
35   absl::Notification client_disconnected;
36   EXPECT_CALL(mock_tunnel, Disconnect)
37       .WillOnce(Invoke([&client_disconnected]() {
38         client_disconnected.Notify();
39         return QboneTunnelInterface::ENDED;
40       }));
41 
42   silo.Quit();
43   client_disconnected.WaitForNotification();
44 
45   silo.Join();
46 }
47 
TEST(QboneTunnelSiloTest,SiloCanShutDownAfterInit)48 TEST(QboneTunnelSiloTest, SiloCanShutDownAfterInit) {
49   MockQboneTunnel mock_tunnel;
50 
51   int iteration_count = 0;
52   EXPECT_CALL(mock_tunnel, WaitForEvents)
53       .WillRepeatedly(Invoke([&iteration_count]() {
54         iteration_count++;
55         return false;
56       }));
57 
58   EXPECT_CALL(mock_tunnel, state)
59       .WillOnce(Return(QboneTunnelInterface::START_REQUESTED))
60       .WillOnce(Return(QboneTunnelInterface::STARTED));
61 
62   absl::Notification client_disconnected;
63   EXPECT_CALL(mock_tunnel, Disconnect)
64       .WillOnce(Invoke([&client_disconnected]() {
65         client_disconnected.Notify();
66         return QboneTunnelInterface::ENDED;
67       }));
68 
69   QboneTunnelSilo silo(&mock_tunnel, true);
70   silo.Start();
71 
72   client_disconnected.WaitForNotification();
73   silo.Join();
74   EXPECT_THAT(iteration_count, Eq(1));
75 }
76 
77 }  // namespace
78 }  // namespace quic
79