Using try finally in nodejs examples, fix CI pipelines (#199)

This commit is contained in:
Pavel 2022-03-21 10:21:46 +03:00 committed by GitHub
parent 6a05fc381a
commit c25674f79c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 249 additions and 128 deletions

7
.github/check_connection.aqua vendored Normal file
View File

@ -0,0 +1,7 @@
service Op("op"):
noop()
func check_connection() -> string:
on HOST_PEER_ID:
Op.noop()
<- "ok"

8
.github/deploy.aqua vendored Normal file
View File

@ -0,0 +1,8 @@
service CallParameters:
call_parameters() -> string
func call(service_id: string) -> string:
on HOST_PEER_ID:
CallParameters service_id
r <- CallParameters.call_parameters()
<- r

84
.github/workflows/check-connection.yml vendored Normal file
View File

@ -0,0 +1,84 @@
name: "check-connection"
on:
push:
# branches:
# - "master"
jobs:
check-deployment:
runs-on: ubuntu-latest
strategy:
matrix:
node: [
'/dns4/kras-00.fluence.dev/tcp/19990/wss/p2p/12D3KooWSD5PToNiLQwKDXsu8JSysCwUt8BVUJEqCHcDe7P5h45e',
'/dns4/kras-00.fluence.dev/tcp/19001/wss/p2p/12D3KooWR4cv1a8tv7pps4HH6wePNaK6gf1Hww5wcCMzeWxyNw51',
'/dns4/kras-01.fluence.dev/tcp/19001/wss/p2p/12D3KooWKnEqMfYo9zvfHmqTLpLdiHXPe4SVqUWcWHDJdFGrSmcA',
'/dns4/kras-02.fluence.dev/tcp/19001/wss/p2p/12D3KooWHLxVhUQyAuZe6AHMB29P7wkvTNMn7eDMcsqimJYLKREf',
'/dns4/kras-03.fluence.dev/tcp/19001/wss/p2p/12D3KooWJd3HaMJ1rpLY1kQvcjRPEvnDwcXrH8mJvk7ypcZXqXGE',
'/dns4/kras-04.fluence.dev/tcp/19001/wss/p2p/12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi',
'/dns4/kras-05.fluence.dev/tcp/19001/wss/p2p/12D3KooWCMr9mU894i8JXAFqpgoFtx6qnV1LFPSfVc3Y34N4h4LS',
'/dns4/kras-06.fluence.dev/tcp/19001/wss/p2p/12D3KooWDUszU2NeWyUVjCXhGEt1MoZrhvdmaQQwtZUriuGN1jTr',
'/dns4/kras-07.fluence.dev/tcp/19001/wss/p2p/12D3KooWEFFCZnar1cUJQ3rMWjvPQg6yMV2aXWs2DkJNSRbduBWn',
'/dns4/kras-08.fluence.dev/tcp/19001/wss/p2p/12D3KooWFtf3rfCDAfWwt6oLZYZbDfn9Vn7bv7g6QjjQxUUEFVBt',
'/dns4/kras-09.fluence.dev/tcp/19001/wss/p2p/12D3KooWD7CvsYcpF9HE9CCV9aY3SJ317tkXVykjtZnht2EbzDPm'
]
fail-fast: false
defaults:
run:
shell: bash
steps:
- name: Checkout repository
uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
~/.cargo/bin
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- run: docker run -d --rm -e RUST_LOG="info" -p 1210:1210 -p 4310:4310 fluencelabs/fluence -t 1210 -w 4310 -k gKdiCSUr1TFGFEgu2t8Ch1XEUsrN5A2UfBLjSZvfci9SPR3NvZpACfcpPGC3eY4zma1pk7UvYv5zb1VjvPHwCjj --local
- name: Download marine
run: sudo bash $GITHUB_WORKSPACE/.github/download_marine.sh
- name: Install Rust
run: |
rustup toolchain install nightly-2021-04-24-x86_64-unknown-linux-gnu
rustup default nightly-2021-04-24-x86_64-unknown-linux-gnu
rustup target add wasm32-wasi --toolchain nightly-2021-04-24-x86_64-unknown-linux-gnu
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-v1-node-16-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-v1-node-16
- name: Setup Node.js 16
uses: actions/setup-node@v1
with:
node-version: 16
- run: npm install -g @fluencelabs/aqua@0.6.4-283
- name: "Check connection to network"
run: |
set -x
NODE=${{ matrix.node }}
INPUT=$GITHUB_WORKSPACE/.github/check_connection.aqua
RESULT=$(aqua run --addr $NODE --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= -f 'check_connection()' --input $INPUT)
RESULT=$(echo $RESULT | sed -e 's/Your peerId: [a-zA-Z0-9]*//g' | xargs)
if [ "$RESULT" != "ok" ]; then
echo "Failed to connect to $NODE"
exit 1
fi
working-directory: marine-examples/call_parameters

View File

@ -37,27 +37,40 @@ jobs:
- uses: actions/cache@v2
with:
path: ~/.npm
key: ${{ runner.os }}-v1-node-14-${{ hashFiles('**/package-lock.json') }}
key: ${{ runner.os }}-v1-node-16-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-v1-node-14
${{ runner.os }}-v1-node-16
- name: Setup Node.js 14
- name: Setup Node.js 16
uses: actions/setup-node@v1
with:
node-version: 14
node-version: 16
- run: npm install -g @fluencelabs/fldist
- run: npm install -g @fluencelabs/aqua@0.6.4-283
- name: "Check call_parameters deployment"
run: |
set -x
export NODE="/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3"
SERVICE_ID=`./deploy.sh`
fldist --node-addr $NODE run_air -d '{"service_id": "'$SERVICE_ID'"}' -p <(echo '
(seq
(call relay (service_id "call_parameters") [] result)
(call %init_peer_id% (returnService "run") [result])
)
')
NODE="/ip4/127.0.0.1/tcp/4310/ws/p2p/12D3KooWKEprYXUXqoV5xSBeyqrWLpQLLH4PXfvVkDJtmcqmh5V3"
SERVICE_ID=`./deploy.sh $NODE`
INPUT=$GITHUB_WORKSPACE/.github/deploy.aqua
RESULT=$(aqua run --addr $NODE --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= -f 'call(service_id)' -d '{"service_id": "'$SERVICE_ID'"}' --input $INPUT)
RESULT=$(echo $RESULT | sed -e 's/Your peerId: [a-zA-Z0-9]*//g')
EXPECTED_PEER_ID=$(echo -e "$RESULT" | sed -n '1p' | grep -o '12D3.*')
RESULT_PEER_ID=$(echo -e "$RESULT" | sed -n '2p' | tr -d \")
if [ "$EXPECTED_PEER_ID" -neq "$RESULT_PEER_ID" ]; then
echo "Expected $EXPECTED_PEER_ID, got $RESULT_PEER_ID"
exit 1
fi
RESULT_SERVICE_ID=$(echo -e "$RESULT" | sed -n '3p')
if [ "$SERVICE_ID" -neq "$RESULT_SERVICE_ID" ]; then
echo "Expected $SERVICE_ID, got $RESULT_SERVICE_ID"
exit 1
fi
aqua dist remove --addr $NODE --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= --id "$SERVICE_ID"
working-directory: marine-examples/call_parameters

View File

@ -10,6 +10,8 @@ jobs:
strategy:
matrix:
node-version: [16.x]
project: [web, nodejs]
fail-fast: false
steps:
- uses: actions/checkout@v2
@ -61,5 +63,4 @@ jobs:
run: |
npm i
CI=false npm run build
npm run test -w nodejs
npm run test -w web
npm run test -w ${{ matrix.project }}

View File

@ -20,6 +20,7 @@ jobs:
"./aqua-examples/price-oracle/client-peer",
"./aqua-examples/price-oracle/web"
]
fail-fast: false
steps:
- uses: actions/checkout@v2

View File

@ -29,65 +29,67 @@ export async function main(environment: Node[]) {
let serviceHost = environment[2];
let providerClient = new FluencePeer();
await providerClient.start({ connectTo: providerHost });
console.log('📘 uploading .wasm to node %s', providerHost.multiaddr);
let path = globSource('../service/artifacts/process_files.wasm');
let { file, swarmAddr, rpcAddr } = await provideFile(path, providerClient);
console.log('📗 swarmAddr', swarmAddr);
console.log('📗 rpcAddr', rpcAddr);
try {
await providerClient.start({ connectTo: providerHost });
console.log('📘 uploading .wasm to node %s', providerHost.multiaddr);
let path = globSource('../service/artifacts/process_files.wasm');
let { file, swarmAddr, rpcAddr } = await provideFile(path, providerClient);
console.log('📗 swarmAddr', swarmAddr);
console.log('📗 rpcAddr', rpcAddr);
await Fluence.start({ connectTo: relay });
console.log(
'📗 created a fluence client %s with relay %s',
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId,
);
await Fluence.start({ connectTo: relay });
console.log(
'📗 created a fluence client %s with relay %s',
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId,
);
// default IPFS timeout is 1 sec, set to 10 secs to retrieve file from remote node
await set_timeout(serviceHost.peerId, 10);
// default IPFS timeout is 1 sec, set to 10 secs to retrieve file from remote node
await set_timeout(serviceHost.peerId, 10);
console.log('\n\n📘 Will deploy ProcessFiles service');
var service_id = await deploy_service(
serviceHost.peerId,
file.cid.toString(),
rpcAddr,
(label, error) => {
console.error('📕 deploy_service failed: ', label, error);
},
{ ttl: 10000 },
);
service_id = fromOption(service_id);
if (service_id === null) {
console.log('\n\n📘 Will deploy ProcessFiles service');
var service_id = await deploy_service(
serviceHost.peerId,
file.cid.toString(),
rpcAddr,
(label, error) => {
console.error('📕 deploy_service failed: ', label, error);
},
{ ttl: 10000 },
);
service_id = fromOption(service_id);
if (service_id === null) {
await Fluence.stop();
await providerClient.stop();
return;
}
console.log('📗 ProcessFiles service is now deployed and available as', service_id);
console.log('\n\n📘 Will upload file & calculate its size');
let { file: newFile } = await provideFile(urlSource('https://i.imgur.com/NZgK6DB.png'), providerClient);
var putResult = await put_file_size(
serviceHost.peerId,
newFile.cid.toString(),
rpcAddr,
service_id,
(fileSize) => console.log('📗 Calculated file size:', fileSize),
(label, error) => {
console.error('📕 put_file_size failed: ', label, error);
},
{ ttl: 10000 },
);
putResult = fromOption(putResult);
if (putResult !== null) {
console.log('📗 File size is saved to IPFS:', putResult);
}
let result = await remove_service(serviceHost.peerId, service_id);
console.log('📗 ProcessFiles service removed', result);
} finally {
await Fluence.stop();
await providerClient.stop();
return;
}
console.log('📗 ProcessFiles service is now deployed and available as', service_id);
console.log('\n\n📘 Will upload file & calculate its size');
let { file: newFile } = await provideFile(urlSource('https://i.imgur.com/NZgK6DB.png'), providerClient);
var putResult = await put_file_size(
serviceHost.peerId,
newFile.cid.toString(),
rpcAddr,
service_id,
(fileSize) => console.log('📗 Calculated file size:', fileSize),
(label, error) => {
console.error('📕 put_file_size failed: ', label, error);
},
{ ttl: 10000 },
);
putResult = fromOption(putResult);
if (putResult !== null) {
console.log('📗 File size is saved to IPFS:', putResult);
}
let result = await remove_service(serviceHost.peerId, service_id);
console.log('📗 ProcessFiles service removed', result);
await Fluence.stop();
await providerClient.stop();
}
function fromOption<T>(opt: T | T[] | null): T | null {

View File

@ -89,40 +89,42 @@ export async function main() {
// console.log("hello");
// setLogLevel('DEBUG');
await Fluence.start({ connectTo: krasnodar[2] });
console.log(
'created a fluence client %s with relay %s',
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId,
);
try {
await Fluence.start({ connectTo: krasnodar[2] });
console.log(
'created a fluence client %s with relay %s',
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId,
);
let echo_result = await echo(names, echo_topos[0].node, echo_topos[0].service_id);
let echo_result = await echo(names, echo_topos[0].node, echo_topos[0].service_id);
let result = '';
let result = '';
for (let item of echo_result) {
result += item.echo + ',';
for (let item of echo_result) {
result += item.echo + ',';
}
console.log('echo result : ', result);
let greeting_result = await greeting(names[0], true, greeting_topos[0].node, greeting_topos[0].service_id);
console.log('greeting result : ', greeting_result);
// echo_greeting_par(greet: bool, echo_service: EchoServiceInput, greeting_services: []NodeServicePair) -> []string:
let seq_result = await echo_greeting_seq(
names,
true,
echo_topos[0].node,
echo_topos[0].service_id,
greeting_topos[0].service_id,
);
console.log('seq result : ', seq_result);
let par_result = await echo_greeting_par(true, echo_service, greeting_services);
console.log('par result : ', par_result);
par_result = await echo_greeting_par_improved(echo_service, greeting_services);
console.log('par improved signature result : ', par_result);
} finally {
await Fluence.stop();
}
console.log('echo result : ', result);
let greeting_result = await greeting(names[0], true, greeting_topos[0].node, greeting_topos[0].service_id);
console.log('greeting result : ', greeting_result);
// echo_greeting_par(greet: bool, echo_service: EchoServiceInput, greeting_services: []NodeServicePair) -> []string:
let seq_result = await echo_greeting_seq(
names,
true,
echo_topos[0].node,
echo_topos[0].service_id,
greeting_topos[0].service_id,
);
console.log('seq result : ', seq_result);
let par_result = await echo_greeting_par(true, echo_service, greeting_services);
console.log('par result : ', par_result);
par_result = await echo_greeting_par_improved(echo_service, greeting_services);
console.log('par improved signature result : ', par_result);
await Fluence.stop();
}

View File

@ -54,29 +54,30 @@ export async function main() {
// Uncomment to enable debug logs:
// setLogLevel('DEBUG');
try {
// create the Fluence client for the Krasnodar testnet
await Fluence.start({ connectTo: krasnodar[5] });
console.log(
'Created a fluence client with peer id %s and relay id %s',
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId,
);
// create the Fluence client for the Krasnodar testnet
await Fluence.start({ connectTo: krasnodar[5] });
console.log(
'Created a fluence client with peer id %s and relay id %s',
Fluence.getStatus().peerId,
Fluence.getStatus().relayPeerId,
);
// call the get_price function -- sequential processing
const network_result = await get_price(
'ethereum',
'usd',
getter_topo[1].node,
getter_topo[1].service_id,
mean_topo[1].service_id,
);
console.log('seq result: ', network_result);
// call the get_price function -- sequential processing
const network_result = await get_price(
'ethereum',
'usd',
getter_topo[1].node,
getter_topo[1].service_id,
mean_topo[1].service_id,
);
console.log('seq result: ', network_result);
// call the get_price_par function -- parallel processing
// func get_price_par(coin: string, currency: string, getter_topo: []NodeServicePair, mean_topo: NodeServicePair) -> Result:
const network_result_par = await get_price_par('ethereum', 'usd', getter_topo, mean_topo[0]);
console.log('par result: ', network_result_par);
await Fluence.stop();
// call the get_price_par function -- parallel processing
// func get_price_par(coin: string, currency: string, getter_topo: []NodeServicePair, mean_topo: NodeServicePair) -> Result:
const network_result_par = await get_price_par('ethereum', 'usd', getter_topo, mean_topo[0]);
console.log('par result: ', network_result_par);
} finally {
await Fluence.stop();
}
}

View File

@ -1,13 +1,15 @@
#!/bin/bash
set -o errexit -o nounset -o pipefail
if [[ -z "${NODE:-}" ]]; then
NODE_ADDR=""
./build.sh
if [ $# -eq 1 ]; then
NODE="$1"
else
NODE_ADDR="--node-addr $NODE"
echo "Expected single argument: node multiaddress. Got $# arguments."
exit 1
fi
./build.sh
# check it .wasm was built
WASM="artifacts/call_parameters.wasm"
@ -15,5 +17,5 @@ test -f "$WASM" || echo >&2 "Couldn't find $WASM"
# create a service from that .wasm
CONFIG="config.json"
SERVICE_ID=$(fldist new_service $NODE_ADDR --modules "$WASM:$CONFIG" --name call_parameters | head -n1 | sed -e 's/service id: //')
SERVICE_ID=$(aqua dist deploy --sk qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqo= --data-path config.json --service call_parameters --addr "$NODE" | tail -n 1 | tr -d \")
echo $SERVICE_ID