rippled
PendingSaves_test.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5  Permission to use, copy, modify, and/or distribute this software for any
6  purpose with or without fee is hereby granted, provided that the above
7  copyright notice and this permission notice appear in all copies.
8  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16 //==============================================================================
17 
18 #include <ripple/app/ledger/PendingSaves.h>
19 #include <ripple/beast/unit_test.h>
20 
21 namespace ripple {
22 namespace test {
23 
24 struct PendingSaves_test : public beast::unit_test::suite
25 {
26  void
28  {
29  PendingSaves ps;
30 
31  // Basic test
32  BEAST_EXPECT(!ps.pending(0));
33  BEAST_EXPECT(!ps.startWork(0));
34  BEAST_EXPECT(ps.shouldWork(0, true));
35  BEAST_EXPECT(ps.startWork(0));
36  BEAST_EXPECT(ps.pending(0));
37  BEAST_EXPECT(!ps.shouldWork(0, false));
38  ps.finishWork(0);
39  BEAST_EXPECT(!ps.pending(0));
40 
41  // Test work stealing
42  BEAST_EXPECT(ps.shouldWork(0, false));
43  BEAST_EXPECT(ps.pending(0));
44  BEAST_EXPECT(ps.shouldWork(0, true));
45  BEAST_EXPECT(ps.pending(0));
46  BEAST_EXPECT(ps.startWork(0));
47  BEAST_EXPECT(!ps.startWork(0));
48  ps.finishWork(0);
49  BEAST_EXPECT(!ps.pending(0));
50  }
51 
52  void
53  run() override
54  {
55  testSaves();
56  }
57 };
58 
60 
61 } // namespace test
62 } // namespace ripple
ripple::test::PendingSaves_test::testSaves
void testSaves()
Definition: PendingSaves_test.cpp:27
ripple::PendingSaves::pending
bool pending(LedgerIndex seq)
Return true if a ledger is in the progress of being saved.
Definition: PendingSaves.h:84
ripple::PendingSaves
Keeps track of which ledgers haven't been fully saved.
Definition: PendingSaves.h:36
ripple::PendingSaves::startWork
bool startWork(LedgerIndex seq)
Start working on a ledger.
Definition: PendingSaves.h:51
ripple::PendingSaves::finishWork
void finishWork(LedgerIndex seq)
Finish working on a ledger.
Definition: PendingSaves.h:74
ripple::PendingSaves::shouldWork
bool shouldWork(LedgerIndex seq, bool isSynchronous)
Check if a ledger should be dispatched.
Definition: PendingSaves.h:99
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::test::PendingSaves_test
Definition: PendingSaves_test.cpp:24
ripple::test::PendingSaves_test::run
void run() override
Definition: PendingSaves_test.cpp:53
ripple::test::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(DeliverMin, app, ripple)