From 2fb08f2cddd064c67b73080960b93be21c36a79f Mon Sep 17 00:00:00 2001
From: Timm Fitschen <t.fitschen@indiscale.com>
Date: Wed, 25 Oct 2023 12:42:48 +0200
Subject: [PATCH] REAPPLY: reapply changes after revert on main

---
 .docker/Dockerfile                         |  3 ++-
 .gitlab-ci.yml                             |  6 +-----
 .gitlab/merge_request_templates/Default.md |  4 +++-
 CHANGELOG.md                               |  2 ++
 README.md                                  |  5 +++++
 conanfile.txt                              |  2 +-
 test/test_async.cpp                        | 18 ++++++++++++------
 test/test_select.cpp                       |  4 +---
 test/test_transaction.cpp                  |  2 --
 9 files changed, 27 insertions(+), 19 deletions(-)

diff --git a/.docker/Dockerfile b/.docker/Dockerfile
index 98f12aa..29e439b 100644
--- a/.docker/Dockerfile
+++ b/.docker/Dockerfile
@@ -15,7 +15,8 @@ RUN rm -rf .git
 
 COPY .docker/caosdb-client.json /caosdb-client.json
 
-# build and run tests
+# Build and run tests.
+# If no other command is given to the Docker image
 CMD mkdir build && \
     cd build && \
     conan install .. -s "compiler.libcxx=libstdc++11" && \
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 8027bef..93e5484 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -78,16 +78,12 @@ build-testenv: &build-testenv
   stage: setup
   timeout: 2h
   needs: []
-  only:
-    - pipelines
-    - schedules
-    - web
   script:
     - *env
     - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
 
       #build testenv image
-    - docker pull $CPPLIB_REGISTRY_IMAGE || { CPPLIB_REGISTRY_IMAGE="$CI_REGISTRY/caosdb/src/caosdb-cpplib/testenv:dev" ; docker pull $CPPLIB_REGISTRY_IMAGE ; }
+    - docker pull $CPPLIB_REGISTRY_IMAGE || { CPPLIB_REGISTRY_IMAGE="$CI_REGISTRY/caosdb/src/caosdb-cpplib/testenv:dev" ; echo "Using cpplib@dev instead."; docker pull $CPPLIB_REGISTRY_IMAGE ; }
     - docker build
       --build-arg CPPLIB_REGISTRY_IMAGE=$CPPLIB_REGISTRY_IMAGE
       --file .docker/Dockerfile
diff --git a/.gitlab/merge_request_templates/Default.md b/.gitlab/merge_request_templates/Default.md
index 35c6d01..3629e0c 100644
--- a/.gitlab/merge_request_templates/Default.md
+++ b/.gitlab/merge_request_templates/Default.md
@@ -28,6 +28,7 @@ guidelines](https://gitlab.com/caosdb/caosdb/-/blob/dev/REVIEW_GUIDELINES.md)
 - [ ] Up-to-date CHANGELOG.md (or not necessary)
 - [ ] Up-to-date JSON schema (or not necessary)
 - [ ] Appropriate user and developer documentation (or not necessary)
+  - Update / write published documentation (`make doc`).
   - How do I use the software?  Assume "stupid" users.
   - How do I develop or debug the software?  Assume novice developers.
 - [ ] Annotations in code (Gitlab comments)
@@ -41,7 +42,8 @@ guidelines](https://gitlab.com/caosdb/caosdb/-/blob/dev/REVIEW_GUIDELINES.md)
 - [ ] I understand the intent of this MR
 - [ ] All automated tests pass
 - [ ] Up-to-date CHANGELOG.md (or not necessary)
-- [ ] Appropriate user and developer documentation (or not necessary)
+- [ ] Appropriate user and developer documentation (or not necessary), also in published
+      documentation.
 - [ ] The test environment setup works and the intended behavior is reproducible in the test
   environment
 - [ ] In-code documentation and comments are up-to-date.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 449e425..fcdf016 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,4 +19,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 ### Fixed
 
+* Fixed failing async test.
+
 ### Security
diff --git a/README.md b/README.md
index 2940e2a..4606072 100644
--- a/README.md
+++ b/README.md
@@ -25,6 +25,11 @@ Create a local conan package from the caosdb-cpplib repository
    path to the pem file in the `CAOSDB_SERVER_CERT` environment variable.
 7. Run with `ctest` in the build directory.
 
+### Troubleshooting ###
+
+- If you don't have `clang-tidy` installed, you can run the first `cmake` command with
+  `LINTING=OFF`: `cmake -D LINTING=OFF -B . ..`
+
 ## Formatting, style, linting ##
 
 `make format`
diff --git a/conanfile.txt b/conanfile.txt
index 54cdf1b..cd80b14 100644
--- a/conanfile.txt
+++ b/conanfile.txt
@@ -1,5 +1,5 @@
 [requires]
-caosdb/0.2.2
+caosdb/[>=0.3.0-dev, include_prerelease=True]
 
 [build_requires]
 gtest/1.11.0
diff --git a/test/test_async.cpp b/test/test_async.cpp
index c804986..bf437f6 100644
--- a/test/test_async.cpp
+++ b/test/test_async.cpp
@@ -53,13 +53,19 @@ TEST(test_async, retrieve_non_existing) {
   auto status = transaction->GetStatus();
   EXPECT_EQ(status.GetCode(), StatusCode::EXECUTING);
 
-  // wait some time
-  std::this_thread::sleep_for(1000ms);
+  // 1000ms are not always sufficient, when there is very high pipeline load.
+  auto count = 1000;
+  auto code = transaction->GetStatus().GetCode();
+  do {
+    // wait some time
+    std::this_thread::sleep_for(10ms);
 
-  // DONT call WaitForIt -> the transaction finishes in the back-ground
-  status = transaction->GetStatus();
-  EXPECT_EQ(status.GetCode(), TransactionStatus::TRANSACTION_ERROR().GetCode());
-  ASSERT_EQ(status.GetCode(), StatusCode::GENERIC_TRANSACTION_ERROR);
+    // DONT call WaitForIt -> the transaction finishes in the background
+    code = transaction->GetStatus().GetCode();
+  } while (--count > 0 && code == StatusCode::EXECUTING);
+  ASSERT_GT(count, 0) << "ERROR: Timeout while waiting for transaction.";
+  EXPECT_EQ(code, TransactionStatus::TRANSACTION_ERROR().GetCode());
+  ASSERT_EQ(code, StatusCode::GENERIC_TRANSACTION_ERROR);
 
   const auto &result_set = transaction->GetResultSet();
 
diff --git a/test/test_select.cpp b/test/test_select.cpp
index f880954..fa63eef 100644
--- a/test/test_select.cpp
+++ b/test/test_select.cpp
@@ -363,9 +363,7 @@ TEST_F(test_select, test_select_property_unit) {
   EXPECT_EQ(query_transaction->GetResultTable().size(), 1);
   for (const auto &row : query_transaction->GetResultTable().GetRows()) {
 
-    // Fails due to https://gitlab.indiscale.com/caosdb/src/caosdb-server/-/issues/264
-    EXPECT_NONFATAL_FAILURE({ EXPECT_EQ(row.GetValue("TestPropDouble.unit").GetAsString(), "m"); },
-                            "TestPropDouble.unit");
+    EXPECT_EQ(row.GetValue("TestPropDouble.unit").GetAsString(), "m");
   }
 }
 
diff --git a/test/test_transaction.cpp b/test/test_transaction.cpp
index aff1c6e..2b1be4c 100644
--- a/test/test_transaction.cpp
+++ b/test/test_transaction.cpp
@@ -1342,11 +1342,9 @@ TEST_F(test_transaction, test_delete_string_id) {
   EXPECT_TRUE(transaction->GetStatus().IsTerminated());
   EXPECT_TRUE(transaction->GetStatus().IsError());
   const auto &results = transaction->GetResultSet();
-  EXPECT_FALSE(results.at(0).HasErrors());
   EXPECT_TRUE(results.at(1).HasErrors());
   EXPECT_EQ(results.at(1).GetErrors().size(), 1);
   EXPECT_EQ(results.at(1).GetErrors().at(0).GetDescription(), "Entity does not exist.");
-  EXPECT_FALSE(results.at(2).HasErrors());
 }
 
 } // namespace caosdb::transaction
-- 
GitLab