-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsmoke-native-plugin.sh
More file actions
executable file
·114 lines (98 loc) · 3.88 KB
/
Copy pathsmoke-native-plugin.sh
File metadata and controls
executable file
·114 lines (98 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env bash
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
workdir="$(mktemp -d)"
server_pid=""
cleanup() {
if [[ -n "${server_pid}" ]] && kill -0 "${server_pid}" 2>/dev/null; then
kill "${server_pid}" 2>/dev/null || true
fi
rm -rf "${workdir}"
}
trap cleanup EXIT
cd "${root}"
cargo build --quiet -p bcode_hello_plugin
case "$(uname -s)" in
Darwin)
dylib="${root}/target/debug/libbcode_hello_plugin.dylib"
;;
Linux)
dylib="${root}/target/debug/libbcode_hello_plugin.so"
;;
MINGW*|MSYS*|CYGWIN*)
dylib="${root}/target/debug/bcode_hello_plugin.dll"
;;
*)
echo "unsupported platform: $(uname -s)" >&2
exit 1
;;
esac
if [[ ! -f "${dylib}" ]]; then
echo "plugin library was not built: ${dylib}" >&2
exit 1
fi
plugin_dir="${workdir}/plugins/hello"
daemon_plugin_dir="${workdir}/config/bcode/plugins/hello"
mkdir -p "${plugin_dir}" "${daemon_plugin_dir}"
cat >"${plugin_dir}/bcode-plugin.toml" <<EOF
id = "example.hello"
name = "Hello Example Plugin"
version = "0.0.1"
[[services]]
description = "Echo service used by smoke tests"
interface_id = "example-hello/v1"
name = "Hello Echo"
[[event_subscriptions]]
topic = "example.event"
[[event_subscriptions]]
topic = "bcode.session.event"
[runtime]
type = "native"
abi_version = 1
library = "${dylib}"
event_symbol = "bcode_plugin_handle_event_v1"
service_symbol = "bcode_plugin_invoke_service_v1"
EOF
cp "${plugin_dir}/bcode-plugin.toml" "${daemon_plugin_dir}/bcode-plugin.toml"
export BCODE_CONFIG="${workdir}/bcode.toml"
cat >"${BCODE_CONFIG}" <<EOF
[plugins]
disabled = ["example.hello"]
EOF
if cargo run --quiet -p bcode -- plugin list --root "${workdir}/plugins" | grep -q "example.hello"; then
echo "disabled plugin should not be listed" >&2
exit 1
fi
cat >"${BCODE_CONFIG}" <<EOF
[plugins]
enabled = ["example.hello"]
EOF
cargo run --quiet -p bcode -- plugin list --root "${workdir}/plugins" | grep -q "example.hello"
cargo run --quiet -p bcode -- plugin services --root "${workdir}/plugins" | grep -q "example-hello/v1"
cargo run --quiet -p bcode -- plugin check --root "${workdir}/plugins" | grep -q $'example.hello\tOK'
cargo run --quiet -p bcode -- plugin invoke --root "${workdir}/plugins" example.hello example-hello/v1 echo "hello service" | grep -q "hello service"
cargo run --quiet -p bcode -- plugin call --root "${workdir}/plugins" example-hello/v1 echo "hello routed service" | grep -q "hello routed service"
cargo run --quiet -p bcode -- plugin publish --root "${workdir}/plugins" example.event "hello event" | grep -q $'delivered\t1'
export XDG_CONFIG_HOME="${workdir}/config"
export BCODE_SOCKET="${workdir}/bcode.sock"
export BCODE_STATE_DIR="${workdir}/state"
cargo run --quiet -p bcode -- server run >"${workdir}/server.log" 2>&1 &
server_pid="$!"
for _ in {1..50}; do
if cargo run --quiet -p bcode -- server status >/dev/null 2>&1; then
break
fi
sleep 0.1
done
cargo run --quiet -p bcode -- plugin services --daemon | grep -q "example-hello/v1"
cargo run --quiet -p bcode -- plugin invoke --daemon example.hello example-hello/v1 echo "hello daemon service" | grep -q "hello daemon service"
cargo run --quiet -p bcode -- plugin call --daemon example-hello/v1 echo "hello daemon routed service" | grep -q "hello daemon routed service"
session_id="$(cargo run --quiet -p bcode -- session create plugin-event-smoke)"
cargo run --quiet -p bcode -- send "${session_id}" "plugin event smoke" >/dev/null
cargo run --quiet -p bcode -- plugin call --daemon example-hello/v1 event-count | grep -q "2"
cargo run --quiet -p bcode -- plugin publish --daemon example.event "daemon event" | grep -q $'delivered\t1'
cargo run --quiet -p bcode -- plugin call --daemon example-hello/v1 event-count | grep -q "3"
cargo run --quiet -p bcode -- server stop >/dev/null
wait "${server_pid}"
server_pid=""
echo "smoke-native-plugin: PASS"