From cfdc32ca06a0c3c3472ed9486cbda4df517686b0 Mon Sep 17 00:00:00 2001
From: Quazgar <quazgar@posteo.de>
Date: Tue, 25 Aug 2020 08:40:33 +0000
Subject: [PATCH] ENH: Test for server issue 99.

Warning: may cause an infinite loop with output in one server thread on failure.
---
 .gitlab-ci.yml              |  2 +-
 CHANGELOG.md                |  3 ++-
 tests/test_issues_server.py | 31 +++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index f5adb28..db924c6 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -31,7 +31,7 @@ stages:
 
 
 # During the test stage the CI pipeline (which runs in a "root" docker) starts
-# two docker container with docker-compose (one for the caosdb-server, another
+# two docker containers with docker-compose (one for the caosdb-server, another
 # for the mysql-backend). Then a third docker is being started which contains
 # the pyintest suite and executes it.
 #
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 998561f..6ea205f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,9 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 * Tests for [caosdb-server#62](https://gitlab.com/caosdb/caosdb-server/-/issues/62)
   in caosdb-server-project, i.e., renaming of a RecordType that should
   be reflected in properties with that RT as datatype.
-- Test for [#39](https://gitlab.com/caosdb/caosdb-server/-/issues/39)
+* Test for [#39](https://gitlab.com/caosdb/caosdb-server/-/issues/39)
   in caosdb server which checks if quoted datetimes in queries are
   evaluated correctly.
+* Test for [caosdb-server#99](https://gitlab.com/caosdb/caosdb-server/-/issues/99).
 
 ### Changed (for changes in existing functionality)
 
diff --git a/tests/test_issues_server.py b/tests/test_issues_server.py
index 2f4b5c5..7b7ebc6 100644
--- a/tests/test_issues_server.py
+++ b/tests/test_issues_server.py
@@ -24,6 +24,10 @@
 
 """Tests for issues on gitlab.com, project caosdb-server."""
 
+import os
+import tempfile
+import time
+
 import caosdb as db
 from caosdb.exceptions import EntityError, TransactionError
 import pytest
@@ -137,3 +141,30 @@ def test_issue_85_b():
     C.update()
     C.add_parent(A)
     C.update()  # Failed at this step
+
+
+def test_issue_99():
+    """Checksum updating failed with versioning enabled.
+    """
+
+    # Using files in extroot, because this allows us to update the file content from the outside.
+    local_dir = os.path.join(db.get_config().get("IntegrationTests",
+                                                 "test_files.test_insert_files_in_dir.local"),
+                             "test_issue_99")
+    docker_dir = os.path.join(db.get_config().get("IntegrationTests",
+                                                  "test_files.test_insert_files_in_dir.server"),
+                              "test_issue_99")
+    os.makedirs(local_dir, exist_ok=True)
+    with tempfile.NamedTemporaryFile(dir=local_dir) as file_99:
+        # Create File entity in CaosDB
+        file_99.write("test 99\n".encode())
+        os.fchmod(file_99.fileno(), 0o744)  # make the file world readable
+        cont = db.Container()
+        cont.insert(unique=False, raise_exception_on_error=False,
+                    flags={"InsertFilesInDir": docker_dir})
+        dbfile = cont[0]
+
+        # Checksum should exist after a short time
+        time.sleep(0.1)
+        dbfile.retrieve()
+        assert dbfile.checksum is not None
-- 
GitLab