<commit_before># Load testing

To set up a load test that will make fake users submit encrypted ballot files, you need to generate these ballot files in advance. A script which does this automatically is available at `tests/load_testing_set_up.py`. Here is an example of usage.

## Set up a load test

### Compile Belenios with debug flag

You need to compile `belenios-tool` with `BELENIOS_DEBUG=1` environment variable, and execute `belenios-tool` with `BELENIOS_USE_URANDOM=1` environment variable, in order to speed up generation of a high amount of ballots files. In these conditions, `belenios-tool` generates random numbers using `/dev/urandom` instead of `/dev/random`, which is much faster and reduces a lot the probability to exhaust the random numbers pool, which would lead to timeout errors when executing `belenios-tool` automatically (using `tests/load_testing_set_up.py`).

```
make clean
_build/sanitize.sh
BELENIOS_DEBUG=1 make all
```

### Start the server

If the Application Under Test is your local Belenios server:

In a local terminal, start your Belenios server:

```
BELENIOS_SENDMAIL=tests/tools/sendmail_fake_to_static.sh demo/run-server.sh
```

Else (the Application Under Test is a distant Belenios server):

SSH into the server machine and start the Belenios server by executing the same kind of command, making sure that the fake sendmail command writes into a text file that is publicly accessible by a URL.

Make sure you have an administrator user account on this Belenios server, so that you can create an election.

### Execute the script that creates the election and generates ballot files and the aggregated votes CSV file

In another local terminal, run:

```
cd /path/to/belenios/git/repository
source venv/bin/activate
```

If the Application Under Test is your local Belenios server:

Execute the script:

````
BELENIOS_USE_URANDOM=1 USE_HEADLESS_BROWSER=0 SENT_EMAILS_TEXT_FILE_ABSOLUTE_PATH=/path/to/_build/src/static/mail.txt FAKE_SENDMAIL_EXECUTABLE_FILE_PATH_RELATIVE_TO_GIT_REPOSITORY=tests/tools/sendmail_fake_to_static.sh FAKE_SENT_EMAILS_FILE_RELATIVE_URL=static/mail.txt python ./tests/load_testing_set_up.py
````

Else (the Application Under Test is a distant Belenios server):

Execute the script:

```
SERVER_URL=https://belenios2.lhs.loria.fr BELENIOS_USE_URANDOM=1 USE_HEADLESS_BROWSER=0 LOGIN_MODE=public ADMINISTRATOR_USERNAME=your_belenios_administrator_user_login ADMINISTRATOR_PASSWORD=<PASSWORD> SENT_EMAILS_TEXT_FILE_ABSOLUTE_PATH=/path/to/belenios/git/repository/_build/src/static/mail.txt FAKE_SENT_EMAILS_FILE_RELATIVE_URL=mail/mails.txt FAKE_SENDMAIL_EXECUTABLE_FILE_PATH_RELATIVE_TO_GIT_REPOSITORY=tests/tools/sendmail_fake_to_static.sh python ./tests/load_testing_set_up.py
```<commit_msg>make common variables appear in command for easier customization<commit_after># Load testing

To set up a load test that will make fake users submit encrypted ballot files, you need to generate these ballot files in advance. A script which does this automatically is available at `tests/load_testing_set_up.py`. Here is an example of usage.

## Set up a load test

### Compile Belenios with debug flag

You need to compile `belenios-tool` with `BELENIOS_DEBUG=1` environment variable, and execute `belenios-tool` with `BELENIOS_USE_URANDOM=1` environment variable, in order to speed up generation of a high amount of ballots files. In these conditions, `belenios-tool` generates random numbers using `/dev/urandom` instead of `/dev/random`, which is much faster and reduces a lot the probability to exhaust the random numbers pool, which would lead to timeout errors when executing `belenios-tool` automatically (using `tests/load_testing_set_up.py`).

```
make clean
_build/sanitize.sh
BELENIOS_DEBUG=1 make all
```

### Start the server

If the Application Under Test is your local Belenios server:

In a local terminal, start your Belenios server:

```
BELENIOS_SENDMAIL=tests/tools/sendmail_fake_to_static.sh demo/run-server.sh
```

Else (the Application Under Test is a distant Belenios server):

SSH into the server machine and start the Belenios server by executing the same kind of command, making sure that the fake sendmail command writes into a text file that is publicly accessible by a URL.

Make sure you have an administrator user account on this Belenios server, so that you can create an election.

### Execute the script that creates the election and generates ballot files and the aggregated votes CSV file

In another local terminal, run:

```
cd /path/to/belenios/git/repository
source venv/bin/activate
```

If the Application Under Test is your local Belenios server:

Adapt and execute the script:

````
BELENIOS_USE_URANDOM=1 USE_HEADLESS_BROWSER=0 SENT_EMAILS_TEXT_FILE_ABSOLUTE_PATH=/path/to/_build/src/static/mail.txt FAKE_SENT_EMAILS_FILE_RELATIVE_URL=static/mail.txt FAKE_SENDMAIL_EXECUTABLE_FILE_PATH_RELATIVE_TO_GIT_REPOSITORY=tests/tools/sendmail_fake_to_static.sh NUMBER_OF_INVITED_VOTERS=500 NUMBER_OF_VOTING_VOTERS=250 python ./tests/load_testing_set_up.py
````

Else (the Application Under Test is a distant Belenios server):

Adapt and execute the script:

```
SERVER_URL=https://belenios2.lhs.loria.fr BELENIOS_USE_URANDOM=1 USE_HEADLESS_BROWSER=0 LOGIN_MODE=public ADMINISTRATOR_USERNAME=your_belenios_administrator_user_login ADMINISTRATOR_PASSWORD=<PASSWORD> SENT_EMAILS_TEXT_FILE_ABSOLUTE_PATH=/path/to/belenios/git/repository/_build/src/static/mail.txt FAKE_SENT_EMAILS_FILE_RELATIVE_URL=mail/mails.txt FAKE_SENDMAIL_EXECUTABLE_FILE_PATH_RELATIVE_TO_GIT_REPOSITORY=tests/tools/sendmail_fake_to_static.sh NUMBER_OF_INVITED_VOTERS=500 NUMBER_OF_VOTING_VOTERS=250 python ./tests/load_testing_set_up.py
```
{'fraction_non_alphanumeric': 0.06588400210268092, 'fraction_numerical': 0.0049062554757315574, 'mean_word_length': 6.090683229813664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7177904', 'n_tokens_mistral': 1878, 'n_tokens_neox': 1807, 'n_words': 588}