Skip to content

Commit 8fe9306

Browse files
committed
Integration tests: use fixtures and abort indeterminate
1 parent 122bcec commit 8fe9306

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

test/cljs/status_im/test/protocol/core.cljs

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
(ns status-im.test.protocol.core
2-
(:require [cljs.test :refer-macros [deftest is testing run-tests async]]
2+
(:require-macros [cljs.core.async.macros :as async])
3+
(:require [cljs.test :refer-macros [deftest is testing run-tests
4+
async use-fixtures]]
35
[cljs.nodejs :as nodejs]
6+
[cljs.core.async :as async]
47
[status-im.protocol.web3.utils :as web3.utils]
58
[status-im.test.protocol.node :as node]
69
[status-im.test.protocol.utils :as utils]
@@ -10,14 +13,28 @@
1013

1114
(nodejs/enable-util-print!)
1215

13-
;; NOTE(oskarth): If status-go has already been built correctly, comment this out
14-
(node/prepare-env!)
15-
1616
(def rpc-url "http://localhost:8645")
1717
(def Web3 (js/require "web3"))
1818
(defn make-web3 []
1919
(Web3. (Web3.providers.HttpProvider. rpc-url)))
2020

21+
(defn setup []
22+
(println "Setup...")
23+
24+
;; NOTE(oskarth): If status-go has already been built correctly, comment this out
25+
(println "Preparing environment...")
26+
(node/prepare-env!)
27+
28+
(println "Start node...")
29+
(node/start!)
30+
31+
(println "Setup done"))
32+
33+
(defn teardown []
34+
(println "Teardown done"))
35+
36+
(use-fixtures :once {:before setup :after teardown})
37+
2138
(defn make-callback [identity done]
2239
(fn [& args]
2340
(is (contains? #{:sent :pending} (first args)))
@@ -41,13 +58,17 @@
4158
:contacts contacts
4259
:post-error-callback (post-error-callback id)})
4360

44-
;; NOTE(oskarth): Test assumes callback is always called, otherwise it won't terminate
45-
;; TODO(oskarth): Add a timeout async function where we fail test if it takes too long to finish
61+
(defn ensure-test-terminates! [timeout done]
62+
(async/go (async/<! (async/timeout (* timeout 1000)))
63+
(println "ERROR: Timeout of" timeout "seconds reached - failing test.")
64+
(is (= :terminate :indeterminate))
65+
(done)))
66+
4667
;; TODO(oskarth): Fix this test, issue with private key not being persisted
47-
#_(deftest test-send-message!
68+
(deftest test-send-message!
4869
(async done
49-
(node/start!)
50-
(let [web3 (make-web3)
70+
(let [timeout 30
71+
web3 (make-web3)
5172
id1-keypair (protocol/new-keypair!)
5273
common-config {:web3 web3
5374
:groups []
@@ -60,6 +81,7 @@
6081
:hashtags []
6182
:pending-messages []}
6283
id1-config (id-specific-config node/identity-1 id1-keypair [] done)]
84+
(ensure-test-terminates! timeout done)
6385
(protocol/init-whisper! (merge common-config id1-config))
6486
(protocol/send-message!
6587
{:web3 web3
@@ -71,7 +93,6 @@
7193
:content "123"
7294
:timestamp 1498723691404}}}))))
7395

74-
;; TODO(oskarth): Add fixtures to start node before running tests against node
7596
(deftest test-whisper-version!
7697
(testing "Whisper version supported"
7798
(async done

0 commit comments

Comments
 (0)