Skip to content

Commit ddcf4c4

Browse files
committed
add instructions for tests
1 parent b89ccb8 commit ddcf4c4

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

README.md

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Before you get started, make sure you have the following dependencies installed:
5151
- Go (>=v1.22) to compile management service and reverse proxy
5252
- Docker (>=v24)
5353
- Make
54+
- a writable directory (tinyFaaS writes temporary files to a `./tmp` directory)
5455

5556
Note that tinyFaaS is intended for Linux hosts (`x86_64` and `arm64`).
5657
Due to limitations of Docker Desktop for Mac, installing and running [`docker-mac-net-connect`](https://github.com/chipmk/docker-mac-net-connect) is necessary to run tinyFaaS on macOS hosts.
@@ -88,32 +89,27 @@ Additionally, we provide scripts to read logs from your function and to wipe all
8889
### Writing Functions
8990

9091
This tinyFaaS prototype only supports functions written for NodeJS 20, Python 3.9, and binary functions.
92+
A good place to get started with writing functions is the selection of test functions in [`./test/fns`](./test/fns/).
9193

9294
#### NodeJS 20
9395

9496
Your function must be supplied as a Node module with the name `fn` that exports a single function that takes the `req` and `res` parameters for request and response, respectively.
9597
`res` supports the `send()` function that has one parameter, a string that is passed to the client as-is.
9698

97-
To get started with functions, use the example _sieve of Eratosthenes_ function in [`./test/fns/sieve-of-eratosthenes`](./tests/fns/sieve-of-eratosthenes).
98-
9999
#### Python 3.9
100100

101101
Your function must be supplied as a file named `fn.py` that exposes a method `fn` that is invoked for every function invocation.
102102
This method must accept a string as an input (that can also be `None`) and must provide a string as a return value.
103103
You may also provide a `requirements.txt` file from which dependencies will be installed alongside your function.
104104
Any other data you provide will be available.
105105

106-
To get started with this type of function, use the example `echo` function in [`./test/fns/echo`](./tests/fns/echo).
107-
108106
#### Binary
109107

110108
Your function must be provided as a `fn.sh` shell script that is invoked for every function call.
111109
This shell script may also call other binaries as needed.
112110
Input data is provided from `stdin`.
113111
Output responses should be provided on `stdout`.
114112

115-
To get started with this type of function, use the example `echo-binary` function in [`./test/fns/echo-binary`](./tests/fns/echo-binary).
116-
117113
### Calling Functions
118114

119115
tinyFaaS supports different application layer protocols at its reverse proxy.
@@ -184,3 +180,46 @@ For example, to use `6000` as the port for the CoAP and deactivate GRPC, run the
184180
```bash
185181
docker run --env COAP_PORT=6000 --env GRPC_PORT=-1 -v /var/run/docker.sock:/var/run/docker.sock -p 8080:8080 --name tinyfaas-mgmt -d tinyfaas-mgmt tinyfaas-mgmt
186182
```
183+
184+
### Tests
185+
186+
The tests in [`./test`](./test) test the end-to-end functionality of tinyFaaS and are expected to complete successfully.
187+
We use these tests during development to ensure no patches break any functionality.
188+
The tests can also serve as documentation on the expected behavior of tinyFaaS.
189+
190+
Running the tests requires:
191+
192+
- Python >3.10 with the `venv` module
193+
- a tinyFaaS binary built for your host
194+
195+
Create a virtual environment for Python and install the necessary dependencies for CoAP and gRPC:
196+
197+
```sh
198+
python3 -m venv .venv
199+
source .venv/bin/activate
200+
python3 -m pip install -r test/requirements.txt
201+
```
202+
203+
If you do not install these requirements, test runs are limited to invocations with HTTP.
204+
205+
Run the tests with:
206+
207+
```sh
208+
$ make test
209+
.............
210+
----------------------------------------------------------------------
211+
Ran 13 tests in 28.063s
212+
213+
OK
214+
```
215+
216+
Tests will output a `.` (dot) for successful tests and `E` or `F` for failed tests.
217+
tinyFaaS output will be written to `tf_test.out`.
218+
219+
On macOS, [`docker-mac-net-connect`](https://github.com/chipmk/docker-mac-net-connect) is necessary to run tinyFaaS.
220+
There is a [known issue in `docker-mac-net-connect`](https://github.com/chipmk/docker-mac-net-connect/issues/36) that silently breaks the tunnel when Docker Desktop enters its resource saver mode.
221+
If you find that tinyFaaS does not start properly on your macOS host, try restarting the tunnel:
222+
223+
```sh
224+
sudo brew services restart docker-mac-net-connect
225+
```

0 commit comments

Comments
 (0)