Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ rec {
dfx = import ./dfx.nix { inherit pkgs userlib-js; };

e2e-tests = import ./e2e/bats { inherit pkgs dfx; };
e2e-tests-ic-ref = import ./e2e/bats { inherit pkgs dfx; use_ic_ref = true; };
node-e2e-tests = import ./e2e/node { inherit pkgs dfx; };

userlib-js = import ./src/userlib/js { inherit pkgs; };
Expand Down
6 changes: 5 additions & 1 deletion e2e/bats/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ pkgs ? import ../../nix { inherit system; }
, system ? builtins.currentSystem
, dfx ? import ../../dfx.nix { inherit pkgs; }
, use_ic_ref ? false
}:
let
e2e = lib.noNixFiles (lib.gitOnlySource ../../. ./.);
Expand All @@ -20,9 +21,10 @@ let
netcat
ps
python3
procps
which
dfx.standalone
];
] ++ lib.optional use_ic_ref ic-ref;
in

builtins.derivation {
Expand All @@ -38,6 +40,8 @@ builtins.derivation {
# We want $HOME/.cache to be in a new temporary directory.
export HOME=$(mktemp -d -t dfx-e2e-home-XXXX)

export USE_IC_REF=${if use_ic_ref then "true" else "false"}

# Timeout of 10 minutes is enough for now. Reminder; CI might be running with
# less resources than a dev's computer, so e2e might take longer.
timeout --preserve-status 600 bats --recursive ${e2e}/* | tee $out
Expand Down
2 changes: 2 additions & 0 deletions e2e/bats/frontend.bash
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ teardown() {
}

@test "dfx start serves a frontend on a port" {
if [ "$USE_IC_REF" = "true" ]; then skip "dfx start cannot serve frontent when using ic-ref"; fi

dfx build --skip-frontend
dfx_start --host 127.0.0.1:12345

Expand Down
2 changes: 2 additions & 0 deletions e2e/bats/print.bash
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ teardown() {
}

@test "print_mo" {
if [ "$USE_IC_REF" = "true" ]; then skip "printing from mo not specified"; fi

install_asset print_mo
dfx_start 2>stderr.txt
dfx build
Expand Down
52 changes: 40 additions & 12 deletions e2e/bats/utils/_.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,30 @@ dfx_new() {

# Start the client in the background.
dfx_start() {
# Bats creates a FD 3 for test output, but child processes inherit it and Bats will
# wait for it to close. Because `dfx start` leaves child processes running, we need
# to close this pipe, otherwise Bats will wait indefinitely.
dfx start --background "$@" 3>&-
local project_dir=${pwd}
local dfx_config_root=.dfx/client-configuration
printf "Configuration Root for DFX: %s\n" "${dfx_config_root}"
test -f ${dfx_config_root}/client-1.port
local port=$(cat ${dfx_config_root}/client-1.port)
if [ "$USE_IC_REF" = "true" ]
then
ic-ref --pick-port --write-port-to port 3>&- &
Comment thread
nomeata marked this conversation as resolved.
echo $! > ic-ref.pid

sleep 5

test -f port
local port=$(cat port)

dfx bootstrap --port 8000 --providers http://127.0.0.1:${port}/api &
echo $! > dfx-bootstrap.pid
else
# Bats creates a FD 3 for test output, but child processes inherit it and Bats will
# wait for it to close. Because `dfx start` leaves child processes running, we need
# to close this pipe, otherwise Bats will wait indefinitely.
dfx start --background "$@" 3>&-
local project_dir=${pwd}
local dfx_config_root=.dfx/client-configuration
printf "Configuration Root for DFX: %s\n" "${dfx_config_root}"
test -f ${dfx_config_root}/client-1.port
local port=$(cat ${dfx_config_root}/client-1.port)
fi

printf "Client Configured Port: %s\n" "${port}"

timeout 5 sh -c \
Expand All @@ -49,8 +64,21 @@ dfx_start() {

# Stop the client and verify it is very very stopped.
dfx_stop() {
dfx stop
if [ "$USE_IC_REF" = "true" ]
then
test -f ic-ref.pid
printf "Killing ic-ref at pid: %u\n" "$(cat ic-ref.pid)"
kill $(cat ic-ref.pid)
rm -f ic-ref.pid

test -f dfx-bootstrap.pid
printf "Killing dfx bootstrap at pid: %u\n" "$(cat dfx-bootstrap.pid)"
kill $(cat dfx-bootstrap.pid)
rm -f dfx-bootstrap.pid
else
dfx stop

# Verify that processes are killed.
! ( ps | grep " [d]fx start" )
# Verify that processes are killed.
! ( ps | grep " [d]fx start" )
fi
}
1 change: 1 addition & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ let
napalm = self.callPackage self.sources.napalm {
pkgs = self // { nodejs = self.nodejs-12_x; };
};
ic-ref = (import self.sources.ic-ref { inherit (self) system; }).ic-ref;

inherit (nixFmt) nix-fmt;
nix-fmt-check = nixFmt.check;
Expand Down
7 changes: 7 additions & 0 deletions nix/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
"rev": "a847ecc0bb8a1893f2cfb8d26dd31d69cb019eb6",
"type": "git"
},
"ic-ref": {
"branch": "legacy2",
"ref": "legacy2",
"repo": "ssh://git@github.com/dfinity-lab/ic-ref",
"rev": "6d8a3f28bdc6969754b354e56fb9caf280d6f887",
"type": "git"
},
"motoko": {
"ref": "master",
"repo": "ssh://git@github.com/dfinity-lab/motoko",
Expand Down