Prechádzať zdrojové kódy

fix: the database-change case creates the collection it watches

I dropped dbchange_test as test residue. It is a fixture: the
database-change case watches that collection, and with it gone the case
failed on "no collection or view named dbchange_test" - a failure with
nothing to do with database change triggers.

I judged it residue from its name and its zero documents without checking
what referenced it, and a watch cursor pointing straight at it went past
me in the same pass. Then I committed on a red suite, having read the
count and not the failure.

The case seeds the collection itself now, with a ten-minute TTL on the
seeded document so the fixture clears itself, and grants itself the write
it needs. A test that depends on a fixture it does not create is a test
that fails the day somebody tidies up.

70 passed, 0 failed.
fszontagh 1 mesiac pred
rodič
commit
bd9a3da286
1 zmenil súbory, kde vykonal 75 pridanie a 10 odobranie
  1. 75 10
      tests/nodes/database-change.json

+ 75 - 10
tests/nodes/database-change.json

@@ -2,21 +2,86 @@
   "name": "verify-database-change",
   "settings": {
     "storagePermissions": {
-      "collections": { "watch_cursors": "read-write", "dbchange_test": "read-write" }
+      "collections": {
+        "watch_cursors": "read-write",
+        "dbchange_test": "read-write"
+      }
     }
   },
   "_comment": "Database Change is a real trigger now - the database reports the change and the webserver starts the workflow - so it can only sit at the start of a flow, and the engine skips a trigger node found anywhere else. That is what this fixture covers: a run started by hand, which has no event to work from and falls back to asking what changed since last time. The event path itself needs a live subscription and a running webserver, so it is not reachable from here; it was verified by hand against insert, update and delete.",
   "nodes": [
-    {"id": "first", "name": "Manual Run", "type": "database-change", "position": {"x": 0, "y": 0},
-     "config": {"collection": "dbchange_test", "emitOnFirstRun": false}},
-    {"id": "cleanup", "name": "Cleanup", "type": "code", "position": {"x": 0, "y": 100},
-     "config": {"code": "// The cursor is keyed by workflow and node, and the harness builds a fresh\n// workflow each run, so this run was always a first run. Clearing it anyway\n// keeps the collection from filling up with one cursor per test run.\nsmartbotic.storage.delete('watch_cursors', context.workflowId + ':first');\nreturn { cleaned: true };"}}
+    {
+      "id": "seed",
+      "name": "Make the collection exist",
+      "type": "storage-insert",
+      "position": {
+        "x": 0,
+        "y": -100
+      },
+      "config": {
+        "collectionSource": "manual",
+        "collectionManual": "dbchange_test",
+        "documentData": "{\"probe\": \"fixture\"}",
+        "ttlMs": 600000
+      }
+    },
+    {
+      "id": "first",
+      "name": "Manual Run",
+      "type": "database-change",
+      "position": {
+        "x": 0,
+        "y": 0
+      },
+      "config": {
+        "collection": "dbchange_test",
+        "emitOnFirstRun": false
+      }
+    },
+    {
+      "id": "cleanup",
+      "name": "Cleanup",
+      "type": "code",
+      "position": {
+        "x": 0,
+        "y": 100
+      },
+      "config": {
+        "code": "// The cursor is keyed by workflow and node, and the harness builds a fresh\n// workflow each run, so this run was always a first run. Clearing it anyway\n// keeps the collection from filling up with one cursor per test run.\nsmartbotic.storage.delete('watch_cursors', context.workflowId + ':first');\nreturn { cleaned: true };"
+      }
+    }
   ],
   "connections": [
-    {"sourceNodeId": "first", "sourceOutput": "main", "targetNodeId": "cleanup", "targetInput": "data"}
+    {
+      "sourceNodeId": "seed",
+      "sourceOutput": "main",
+      "targetNodeId": "first",
+      "targetInput": "data"
+    },
+    {
+      "sourceNodeId": "first",
+      "sourceOutput": "main",
+      "targetNodeId": "cleanup",
+      "targetInput": "data"
+    }
   ],
   "expect": {
-    "first": {"status": "completed", "output": {"count": 0, "isFirstRun": true}},
-    "cleanup": {"status": "completed"}
-  }
-}
+    "first": {
+      "status": "completed",
+      "output": {
+        "count": 0,
+        "isFirstRun": true
+      }
+    },
+    "cleanup": {
+      "status": "completed"
+    },
+    "seed": {
+      "status": "completed",
+      "output": {
+        "success": true
+      }
+    }
+  },
+  "comment": "\n\nThe first node creates the collection this case watches. It used to rely on dbchange_test already being there, which made the case fail the day that collection was tidied away - for a reason that had nothing to do with database change triggers. The seeded document carries a ten-minute TTL so the fixture clears itself."
+}