forked from advancedtelematic/aktualizr
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from cajun-rat/api-queue-refactor
RFC: ApiQueue refactor
- Loading branch information
Showing
5 changed files
with
172 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include <gtest/gtest.h> | ||
|
||
#include <chrono> | ||
#include <string> | ||
#include "utilities/apiqueue.h" | ||
|
||
using std::cout; | ||
using std::future; | ||
using std::future_status; | ||
|
||
class CheckLifetime { | ||
public: | ||
CheckLifetime() { cout << "ctor\n"; } | ||
~CheckLifetime() { | ||
valid = 999; | ||
cout << "dtor\n"; | ||
} | ||
CheckLifetime(const CheckLifetime& other) { | ||
(void)other; | ||
cout << "copy-ctor\n"; | ||
} | ||
CheckLifetime& operator=(const CheckLifetime&) = delete; | ||
CheckLifetime& operator=(CheckLifetime&&) = delete; | ||
CheckLifetime(CheckLifetime&&) = delete; | ||
|
||
int valid{100}; | ||
}; | ||
|
||
TEST(ApiQueue, Simple) { | ||
api::CommandQueue dut; | ||
future<int> result; | ||
{ | ||
CheckLifetime checkLifetime; | ||
std::function<int()> task([checkLifetime] { | ||
cout << "Running task..." << checkLifetime.valid << "\n"; | ||
return checkLifetime.valid; | ||
}); | ||
result = dut.enqueue(std::move(task)); | ||
cout << "Leaving scope.."; | ||
} | ||
EXPECT_EQ(result.wait_for(std::chrono::milliseconds(100)), future_status::timeout); | ||
|
||
dut.run(); | ||
// Include a timeout to avoid a failing test handing forever | ||
ASSERT_EQ(result.wait_for(std::chrono::seconds(10)), future_status::ready); | ||
EXPECT_EQ(result.get(), 100); | ||
} | ||
|
||
#ifndef __NO_MAIN__ | ||
int main(int argc, char** argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters