From 1e733301ecd65abae7fec8b91ac7c855437c741d Mon Sep 17 00:00:00 2001
From: Frederik Ring <frederik.ring@wikimedia.de>
Date: Mon, 30 Oct 2023 13:25:16 +0100
Subject: [PATCH] test: add debug log

---
 .github/workflows/docker.test.yml | 10 ++++-
 docker-compose.ci.yml             |  6 +--
 seeder/server.js                  | 70 +++++++++++++++++--------------
 3 files changed, 50 insertions(+), 36 deletions(-)

diff --git a/.github/workflows/docker.test.yml b/.github/workflows/docker.test.yml
index 054be0d..f2cefd1 100644
--- a/.github/workflows/docker.test.yml
+++ b/.github/workflows/docker.test.yml
@@ -27,7 +27,15 @@ jobs:
           max_attempts: 100
           retry_wait_seconds: 2
           warning_on_retry: false
-          command: if (($(docker-compose ${{ env.COMPOSE_ARGS }} logs wdqs-updater | grep "org.wikidata.query.rdf.tool.Updater - Polled" | wc -l) >= 10)); then exit 0; else exit 1; fi
+          command: |
+            docker-compose ${{ env.COMPOSE_ARGS }} logs wdqs-updater
+            line_count=$(docker-compose ${{ env.COMPOSE_ARGS }} logs wdqs-updater | grep "org.wikidata.query.rdf.tool.Updater - Polled" | wc -l)
+            echo "line count: $line_count"
+            if [ $line_count -gt 10 ]; then
+              exit 0;
+            else
+              exit 1;
+            fi
       - name: Make a sparql request
         run: |
           NUM_BINDINGS=$(curl 'http://localhost:9999/bigdata/namespace/wdq/sparql' -H 'Accept: application/sparql-results+json' --data-raw 'query=SELECT+*+WHERE%7B+%3Fs+%3Fp+%3Fo+%7D' | jq '.results.bindings | length')
diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml
index bd8c3df..d252c44 100644
--- a/docker-compose.ci.yml
+++ b/docker-compose.ci.yml
@@ -27,9 +27,9 @@ services:
     environment:
       - WBSTACK_WIKIBASE_SCHEME=http
       - WBSTACK_LOOP_LIMIT=100
-      - WBSTACK_API_ENDPOINT=http://api.svc:3030
-      - WBSTACK_API_ENDPOINT_MARK_FAILED=http://api.svc:3030
-      - WBSTACK_API_ENDPOINT_MARK_DONE=http://api.svc:3030
+      - WBSTACK_API_ENDPOINT=http://api.svc:3030/getBatches
+      - WBSTACK_API_ENDPOINT_MARK_FAILED=http://api.svc:3030/markFailed
+      - WBSTACK_API_ENDPOINT_MARK_DONE=http://api.svc:3030/markDone
       - WBSTACK_BATCH_SLEEP=1
       - WIKIBASE_HOST=wikibase.svc
       - HEAP_SIZE=32m
diff --git a/seeder/server.js b/seeder/server.js
index 00c55ec..a8587f7 100644
--- a/seeder/server.js
+++ b/seeder/server.js
@@ -1,41 +1,47 @@
 var http = require('http');
-const wbEdit = require( 'wikibase-edit' )( require( './wikibase-edit.config' ) );
+const wbEdit = require('wikibase-edit')(require('./wikibase-edit.config'));
 
-var x = 0
 http.createServer(async function (req, res) {
-    res.writeHead(200, {'Content-Type': 'text/json'});
+    switch (req.path) {
+    case '/getBatches':
+        numEntities = 20;
+        entities = [];
 
-    numEntities = 20;
-    entities = [];
+        for (var i=1; i <= numEntities; ++i) {
+            const { entity } = await wbEdit.entity.create({
+                type: 'item',
+                labels: {
+                    'en': new Date().toISOString()
+                },
+                descriptions: {
+                    'en': new Date().toDateString() + new Date().toISOString()
+                }
+            });
 
-    for(var i=1; i <= numEntities; ++i){
-        const { entity } = await wbEdit.entity.create({
-            type: 'item',
-            labels: {
-                'en': new Date().toISOString()
-            },
-            descriptions: {
-                'en': new Date().toDateString() + new Date().toISOString()
-            }
-        });
-
-        console.log('created item id', entity.id)
-        entities.push(entity.id)
-    }
+            console.log('created item id', entity.id)
+            entities.push(entity.id)
+        }
 
-    x += numEntities;
-    console.log(new Date().toISOString());
+        console.log(new Date().toISOString());
 
-    responseObject = {
-        'entityIds': entities.join(','),
-        'wiki': {
-            'domain': process.env.API_WIKIBASE_DOMAIN,
-            'wiki_queryservice_namespace': {
-                'backend': process.env.API_WDQS_BACKEND,
-                'namespace': 'wdq'
-            }
-        },
+        responseObject = {
+            'entityIds': entities.join(','),
+            'wiki': {
+                'domain': process.env.API_WIKIBASE_DOMAIN,
+                'wiki_queryservice_namespace': {
+                    'backend': process.env.API_WDQS_BACKEND,
+                    'namespace': 'wdq'
+                }
+            },
 
-    };
-    res.end(JSON.stringify([responseObject]));
+        };
+        res.end(JSON.stringify([responseObject]));
+    case '/markFailed':
+    case '/markDone':
+        res.writeHead(200);
+        res.end('1');
+    default:
+        res.writeHead(404);
+        res.end('Not found');
+    }
 }).listen(3030);