| 12 | using Clock = std::chrono::steady_clock; |
| 13 | |
| 14 | int EtlLoggerTest(std::unique_ptr<pmapi::Session> pSession) |
| 15 | { |
| 16 | auto& opt = clio::Options::Get(); |
| 17 | |
| 18 | std::string line; |
| 19 | |
| 20 | // ping gate to sync on init finished |
| 21 | std::getline(std::cin, line); |
| 22 | if (line != "%ping") { |
| 23 | std::cout << "%%{ping-error}%%" << std::endl; |
| 24 | return -1; |
| 25 | } |
| 26 | std::cout << "%%{ping-ok}%%" << std::endl; |
| 27 | |
| 28 | std::optional<PM_STATUS> errorStatus; |
| 29 | pmapi::EtlLogger logger; |
| 30 | |
| 31 | try { |
| 32 | if (opt.runTime && opt.outputPath) { |
| 33 | logger = pSession->StartEtlLogging(); |
| 34 | std::this_thread::sleep_for(1s * *opt.runTime); |
| 35 | logger.Finish(*opt.outputPath); |
| 36 | } |
| 37 | } |
| 38 | catch (const pmapi::ApiErrorException& e) { |
| 39 | if (!opt.testExpectError) { |
| 40 | throw; |
| 41 | } |
| 42 | errorStatus = e.GetCode(); |
| 43 | } |
| 44 | |
| 45 | // if we captured an error, wait here for error ack |
| 46 | if (errorStatus) { |
| 47 | std::getline(std::cin, line); |
| 48 | if (line != "%err-check") { |
| 49 | std::cout << "%%{err-check-error}%%" << std::endl; |
| 50 | return -1; |
| 51 | } |
| 52 | auto&& err = pmapi::EnumMap::GetKeyMap(PM_ENUM_STATUS)->at(*errorStatus).narrowSymbol; |
| 53 | std::cout << "%%{err-check-ok:" << err << "}%%" << std::endl; |
| 54 | } |
| 55 | |
| 56 | if (opt.runTime) { |
| 57 | std::this_thread::sleep_for(1ms * *opt.runTime); |
| 58 | } |
| 59 | |
| 60 | // wait for command |
| 61 | while (std::getline(std::cin, line)) { |
| 62 | if (line == "%quit") { |
| 63 | std::cout << "%%{quit-ok}%%" << std::endl; |
| 64 | std::this_thread::sleep_for(25ms); |
| 65 | return 0; |
| 66 | } |
| 67 | else { |
| 68 | std::cout << "%%{err-bad-command}%%" << std::endl; |
| 69 | } |
| 70 | } |
| 71 |
no test coverage detected