From 1fa4eb432ef27e31c46f2a2ad01b327c1c1c2add Mon Sep 17 00:00:00 2001
From: Corey Rice <coreyarice@gmail.com>
Date: Mon, 23 Oct 2023 08:05:48 -0300
Subject: [PATCH] fix(ci): increase retries on failing healthcheck

---
 .github/workflows/ci.yaml             |  5 +++++
 docker-compose.yaml                   | 16 ++++++++--------
 hardhat-healthcheck.js                | 12 +++++++++---
 package.json                          |  1 +
 subgraphs/isolated-pools/package.json |  1 -
 5 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index 18862d39..bef862ac 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -107,6 +107,11 @@ jobs:
       - name: Run Governance integration integration tests
         run: |
           docker exec -i subgraph-hardhat-node yarn workspace venus-governance-subgraph run test:integration --bail
+
+      - name: Debug
+        if: always()
+        run: |
+          docker inspect --format "{{json .State.Health }}" $(docker-compose ps -q hardhat)
       
       - name: Stop containers
         if: always()
diff --git a/docker-compose.yaml b/docker-compose.yaml
index a7bcee46..6e40b924 100644
--- a/docker-compose.yaml
+++ b/docker-compose.yaml
@@ -15,11 +15,11 @@ services:
         condition: service_started
       postgres:
         condition: service_started
-    healthcheck:
-        test: ["CMD", "curl", "-f", "http://graph-node:8000"]
-        interval: 30s
-        timeout: 12s
-        retries: 10
+    # healthcheck:
+    #     test: ["CMD", "curl", "-f", "http://graph-node:8000"]
+    #     interval: 30s
+    #     timeout: 12s
+    #     retries: 10
     environment:
       postgres_host: postgres
       postgres_user: graph-node
@@ -38,7 +38,7 @@ services:
       - sh
       - -c
       - |
-        yarn &&PACKAGE=isolated-pools yarn workspace isolated-pools-subgraph run hardhat node --hostname 0.0.0.0
+        yarn && PACKAGE=isolated-pools yarn run node:integration
 # Installing again to link workspaces
     ports:
       - 8545:8545
@@ -49,8 +49,8 @@ services:
     healthcheck:
         test: ["CMD", "node", "./hardhat-healthcheck.js"]
         interval: 30s
-        timeout: 12s
-        retries: 10
+        timeout: 20s
+        retries: 20
   ipfs:
     image: ipfs/go-ipfs:v0.4.23
     ports:
diff --git a/hardhat-healthcheck.js b/hardhat-healthcheck.js
index 118cc3a3..8aeebb08 100755
--- a/hardhat-healthcheck.js
+++ b/hardhat-healthcheck.js
@@ -4,9 +4,15 @@
  * If node is up this function will silently succeed. If the node is down it will throw an error.
  */
 async function healthCheck() {
-  const ethers = require('ethers');
-  const localProvider = new ethers.providers.JsonRpcProvider(`http://hardhat:8545`)
-  localBlockNum = await localProvider.getBlockNumber();
+  try {
+    const ethers = require('ethers');
+    const localProvider = new ethers.providers.JsonRpcProvider(`https://hardhat:8545`)
+    localBlockNum = await localProvider.getBlockNumber();
+    console.log(localBlockNum)
+  } catch (e) {
+    console.log(e)
+    throw e
+  }
 }
 
 module.export = healthCheck();
diff --git a/package.json b/package.json
index a8812d74..5a8c4d57 100644
--- a/package.json
+++ b/package.json
@@ -29,6 +29,7 @@
     "lint:fix": "yarn lint --fix",
     "pretty": "prettier '**/*.ts' --write",
     "test": "yarn workspaces foreach run test",
+    "node:integration": "PACKAGE=isolated-pools hardhat node --hostname 0.0.0.0",
     "test:integration": "yarn workspaces foreach run test:integration",
     "postinstall": "patch-package && ./copy_contracts.sh"
   },
diff --git a/subgraphs/isolated-pools/package.json b/subgraphs/isolated-pools/package.json
index 7f0ea0a4..f42016f9 100644
--- a/subgraphs/isolated-pools/package.json
+++ b/subgraphs/isolated-pools/package.json
@@ -31,7 +31,6 @@
     "generate-subgraph-types": "rm -rf /subgraph-client/.graphclient && yarn graphclient build --dir ./subgraph-client",
     "pretty": "prettier —-write '**/*.ts'",
     "test": "yarn prepare:local && graph test",
-    "node:integration": "PACKAGE=isolated-pools hardhat node --hostname 0.0.0.0",
     "test:integration": "PACKAGE=isolated-pools hardhat test tests/integration/index.ts --network localhost"
   },
   "devDependencies": {