Skip to content
Snippets Groups Projects
Commit a38c2f75 authored by DISSOUBRAY Nathan's avatar DISSOUBRAY Nathan Committed by DETCHART Jonathan
Browse files

Adds some tests

parent 9d476112
Branches
Tags
1 merge request!2Adds a CI to run tests
target/
Cargo.lock
Dockerfile
image: "gitlab-registry.isae-supaero.fr/j.detchart/dragoonfly"
stages:
- fmt
- test
variables:
NUSHELL_ARCH: "x86_64-unknown-linux-musl"
NUSHELL_VERSION: "0.91.0"
workflow:
rules:
- if: $CI_COMMIT_MESSAGE =~ /^(draft|no-ci):/
when: never
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: ($CI_PIPELINE_SOURCE == "push") && ($CI_COMMIT_BRANCH == "main")
fmt:
stage: fmt
script:
- make fmt-check
test:
stage: test
needs:
- fmt
before_script:
- apt update --yes
- apt upgrade --yes
- apt install protobuf-compiler --yes
- export NUSHELL_BUILD="nu-$NUSHELL_VERSION-$NUSHELL_ARCH"
- export PATH="/tmp/:$PATH"
# install Nushell
- curl -fLo /tmp/nu.tar.gz "https://github.com/nushell/nushell/releases/download/$NUSHELL_VERSION/$NUSHELL_BUILD.tar.gz"
- tar xvf /tmp/nu.tar.gz --directory /tmp
- cp "/tmp/$NUSHELL_BUILD/nu" /tmp/nu
- make show
script:
- make check
- echo "HTTP_PROXY = ${HTTP_PROXY}"
- echo "http_proxy = ${http_proxy}"
- echo "HTTPS_PROXY = ${HTTPS_PROXY}"
- echo "https_proxy = ${https_proxy}"
- unset HTTP_PROXY
- unset http_proxy
- unset HTTPS_PROXY
- unset https_proxy
- echo "HTTP_PROXY = ${HTTP_PROXY}"
- echo "http_proxy = ${http_proxy}"
- echo "HTTPS_PROXY = ${HTTPS_PROXY}"
- echo "https_proxy = ${https_proxy}"
- make test
FROM rust:latest
EXPOSE 3000:3010
EXPOSE 31200:31210
\ No newline at end of file
Makefile 0 → 100644
.PHONY: fmt fmt-check check test show show-proxy unset-proxy
DEFAULT_GOAL: fmt-check check clippy test
fmt-check:
cargo fmt --all -- --check
fmt:
cargo fmt --all
check:
cargo check --workspace
test:
nu tests/message_exchange.nu
show:
rustup --version
rustup show --verbose
rustc --version
cargo --version
cargo clippy --version
nu --version
show-proxy:
@echo "HTTP_PROXY = ${HTTP_PROXY}"
@echo "http_proxy = ${http_proxy}"
@echo "HTTPS_PROXY = ${HTTPS_PROXY}"
@echo "https_proxy = ${https_proxy}"
unset-proxy:
unset HTTP_PROXY
unset http_proxy
unset HTTPS_PROXY
unset https_proxy
export-proxy:
export HTTP_PROXY='proxy.isae.fr:3128'
\ No newline at end of file
......@@ -7,19 +7,19 @@ const HTTP = {
const DEFAULT_IP = "127.0.0.1:3000"
def "http get-curl" [url: string, --allow-errors, --full]: nothing -> record<body: string, status: int> {
$url
| str replace --all ' ' "%20"
| curl -i $in
| lines
| split list ""
| update 0 { get 0 | parse "HTTP/{v} {c} {m}" | into record }
| update 1 { get 0 }
| {
body: ($in.1 | str replace --regex '^"' '' | str replace --regex '"$' '' | from json),
status: ($in.0.c | into int),
}
}
# def "http get-curl" [url: string, --allow-errors, --full]: nothing -> record<body: string, status: int> {
# $url
# | str replace --all ' ' "%20"
# | curl -i $in
# | lines
# | split list ""
# | update 0 { get 0 | parse "HTTP/{v} {c} {m}" | into record }
# | update 1 { get 0 }
# | {
# body: ($in.1 | str replace --regex '^"' '' | str replace --regex '"$' '' | from json),
# status: ($in.0.c | into int),
# }
# }
def run-command [node: string]: string -> any {
let command = $in
......@@ -31,7 +31,8 @@ def run-command [node: string]: string -> any {
| insert scheme "http"
| insert path $command
| url join
| http get-curl $in --allow-errors --full
| http get $in --allow-errors --full
#| http get-curl $in --allow-errors --full
if $res.status == $HTTP.NOT_FOUND {
error make --unspanned {
......
......@@ -155,9 +155,9 @@ impl ConnectionHandler for Handler {
self.network_send_task.remove(id);
}
if let Some(peer) = shard_sent {
return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(DragoonEvent::Sent {
peer,
}));
return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(
DragoonEvent::Sent { peer },
));
}
to_remove.clear();
......@@ -180,9 +180,9 @@ impl ConnectionHandler for Handler {
}
if let Some(s) = shard_received {
return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(DragoonEvent::Received {
shard: s,
}));
return Poll::Ready(ConnectionHandlerEvent::NotifyBehaviour(
DragoonEvent::Received { shard: s },
));
}
return Poll::Pending;
}
......
......@@ -360,8 +360,11 @@ impl DragoonNetwork {
.start_providing(shard.hash.into())
.unwrap();
}
}
SwarmEvent::Behaviour(DragoonBehaviourEvent::RequestResponse(Event::Message{peer, message})) => match message {
},
SwarmEvent::Behaviour(DragoonBehaviourEvent::RequestResponse(Event::Message {
peer,
message,
})) => match message {
Message::Request {
request, channel, ..
} => {
......@@ -406,10 +409,9 @@ impl DragoonNetwork {
} else {
error!("could not find {} in the request files", request_id);
}
}
}
}
},
e => warn!("[unknown event] {:?}", e),
}
}
......@@ -713,14 +715,18 @@ impl DragoonNetwork {
error!("Cannot send result");
}
}
}
},
DragoonCommand::DragoonGet {
peerid,
key,
sender
sender,
} => match PeerId::from_str(peerid.as_str()) {
Ok(peer) => {
let request_id = self.swarm.behaviour_mut().request_response.send_request(&peer, FileRequest(key));
let request_id = self
.swarm
.behaviour_mut()
.request_response
.send_request(&peer, FileRequest(key));
self.pending_request_file.insert(request_id, sender);
}
Err(err) => {
......@@ -728,7 +734,7 @@ impl DragoonNetwork {
error!("Cannot send result");
}
}
}
},
}
}
}
......@@ -15,7 +15,8 @@ export def "swarm create" [n: int]: nothing -> table {
# run a swarm
export def "swarm run" [
swarm: table<ip_port: string, seed: int, multiaddr: string>, # the table of nodes to run
--features: list<string> = [] # features to include in the nodes
--features: list<string> = [], # features to include in the nodes
--no-shell
]: nothing -> nothing {
if ($swarm | is-empty) {
error make --unspanned {
......@@ -38,6 +39,8 @@ export def "swarm run" [
+ $"1> ($log_dir)/($node.seed).log 2> /dev/null &"
)
}
if not $no_shell {
^$nu.current-exe --execute $'
$env.PROMPT_COMMAND = "SWARM-CONTROL-PANEL"
$env.NU_LOG_LEVEL = "DEBUG"
......@@ -46,6 +49,7 @@ export def "swarm run" [
use swarm.nu ["swarm kill", "swarm list", "swarm log", "bytes decode"]
const SWARM = ($swarm | to nuon)
'
}
null
}
......@@ -89,14 +93,15 @@ export def "swarm log" []: nothing -> table<date: datetime, level: string, id: i
}
# kill the swarm
export def "swarm kill" []: nothing -> nothing {
export def "swarm kill" [--no-shell]: nothing -> nothing {
ps | where name =~ $NAME | each {|it|
log warning $"killing ($it.pid)"
kill $it.pid
}
if not $no_shell {
exit
}
}
# decode a list of integer bytes into the underlying encoded string
export def "bytes decode" [encoding: string = "utf-8"]: list<int> -> string {
......
use ../swarm.nu *
use ../app.nu
use std assert
# define variables
let SWARM = swarm create 2
let record_name = "tata"
let message = "it works at least"
# create the nodes
swarm run --no-shell $SWARM
print "Sleeping for 1s to setup ports"
sleep 1sec
print "Resuming execution"
print "Env var inside the script"
try {
print $'http_proxy: ($env.http_proxy)'
} catch {
print "http_proxy not set"
}
try {
print $'HTTP_PROXY: ($env.HTTP_PROXY)'
} catch {
print "HTTP_PROXY not set"
}
# make the node start to listen on their own ports
print "Node 0 listening"
app listen --node $SWARM.0.ip_port $SWARM.0.multiaddr
print "Node 1 listening"
app listen --node $SWARM.1.ip_port $SWARM.1.multiaddr
# connect the nodes
print "Node 0 dialing node 1"
app dial --node $SWARM.0.ip_port $SWARM.1.multiaddr
# announce that you provide a key and add a message with the given key
print "Node 0 announces it has a given record"
app start-provide --node $SWARM.0.ip_port $record_name
print "Sleeping for 1s"
sleep 1sec
print "Node 0 gives a value associated with the record key"
app put-record --node $SWARM.0.ip_port $record_name $message
# get the value associated to the key
print "Node 1 searches for the value associated with the record key"
let res = app get-record --node $SWARM.1.ip_port $record_name | bytes decode
print "Killing the swarm"
swarm kill --no-shell
assert equal $res $message
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment