From e5d9051131580ef1e75c974d726c2a75f15c24e9 Mon Sep 17 00:00:00 2001 From: Sergey Yakubov <sergey.yakubov@desy.de> Date: Mon, 10 May 2021 12:41:17 +0200 Subject: [PATCH] rollback strem_info on non-existing stream behavior --- common/cpp/src/database/mongodb_client.cpp | 3 +++ .../automatic/producer/python_api/producer_api.py | 15 ++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/cpp/src/database/mongodb_client.cpp b/common/cpp/src/database/mongodb_client.cpp index 43a975318..2d27c3c87 100644 --- a/common/cpp/src/database/mongodb_client.cpp +++ b/common/cpp/src/database/mongodb_client.cpp @@ -428,6 +428,9 @@ Error MongoDBClient::GetStreamInfo(const std::string &collection, StreamInfo* in std::string last_record_str, earliest_record_str; auto err = GetRecordFromDb(collection, 0, GetRecordMode::kLast, &last_record_str); if (err) { + if (err == DBErrorTemplates::kNoRecord) { // with noRecord error it will return last_id = 0 which can be used to understand that the stream is not started yet + return nullptr; + } return err; } err = GetRecordFromDb(collection, 0, GetRecordMode::kEarliest, &earliest_record_str); diff --git a/tests/automatic/producer/python_api/producer_api.py b/tests/automatic/producer/python_api/producer_api.py index 10c981da4..2d6de1c53 100644 --- a/tests/automatic/producer/python_api/producer_api.py +++ b/tests/automatic/producer/python_api/producer_api.py @@ -187,19 +187,20 @@ info = producer.stream_info('stream') assert_eq(info['lastId'], 3, "last id from different stream") assert_eq(info['finished'], True, "stream finished") +info = producer.stream_info('not_exist') +assert_eq(info['lastId'], 0, "last id from non existing stream") + + info_last = producer.last_stream() assert_eq(info_last['name'], "stream", "last stream") assert_eq(info_last['timestampCreated'] <= info_last['timestampLast'], True, "last is later than first") #delete_streams producer.delete_stream('stream') -try: - producer.stream_info('stream') -except asapo_producer.AsapoWrongInputError as e: - print(e) -else: - print("should be error on stream info after stream was deleted") - sys.exit(1) +producer.stream_info('stream') +assert_eq(info['lastId'], 0, "last id from non deleted stream") + + producer.delete_stream('unknown_stream',error_on_not_exist = False) try: producer.delete_stream('unknown_stream',error_on_not_exist = True) -- GitLab