Prechádzať zdrojové kódy

Merge pull request #1640 from mnaamani/storage-node/test-retry

storage-node integration tests: retry on wait for ipfs registration
shamil-gadelshin 4 rokov pred
rodič
commit
9a73fa91db

+ 14 - 5
.github/workflows/run-network-tests.yml

@@ -203,8 +203,17 @@ jobs:
         run: docker-compose --file docker-compose-with-storage.yml up -d
       - name: Add development storage node and initialize content directory
         run: DEBUG=* yarn storage-cli dev-init
-      - name: Wait for storage-node to publish identity
-        run: sleep 90
-        # Better would be poll `http://localhost:3001/discover/v0/1` until we get 200 Response
-      - name: Upload a file
-        run: DEBUG=joystream:* yarn storage-cli upload ./pioneer/packages/apps/public/images/default-thumbnail.png 1 0
+      - name: Try uploading
+        run: |
+          WAIT_TIME=90
+          export DEBUG=joystream:*
+          for i in {1..4}; do
+            [ "$i" == "4" ] && exit -1
+            echo "Waiting for ipfs name registration"
+            sleep ${WAIT_TIME}
+            if yarn storage-cli upload ./pioneer/packages/apps/public/images/default-thumbnail.png 1 0; then
+              break
+            else
+              echo "Upload test failed, will retry"
+            fi
+          done

+ 1 - 1
storage-node/packages/cli/src/cli.ts

@@ -104,7 +104,7 @@ const commands = {
 
 // Entry point.
 export async function main() {
-  const api = await RuntimeApi.create()
+  const api = await RuntimeApi.create({ retries: 3 })
 
   // Simple CLI commands
   const command = cli.input[0]

+ 8 - 2
storage-node/packages/runtime-api/index.js

@@ -55,14 +55,20 @@ class RuntimeApi {
     options = options || {}
 
     const provider = new WsProvider(options.provider_url || 'ws://localhost:9944')
-
+    let attempts = 0
     // Create the API instrance
     while (true) {
+      attempts++
+
+      if (options.retries && attempts > options.retries) {
+        throw new Error('Timeout trying to connect to node')
+      }
+
       try {
         this.api = await ApiPromise.create({ provider, types: types })
         break
       } catch (err) {
-        debug('connecting to node failed, will retry..')
+        debug('Connecting to node failed, will retry..')
       }
       await sleep(5000)
     }