Skip to content

Instantly share code, notes, and snippets.

@thomaspaulb
Created January 21, 2024 21:42
Show Gist options
  • Save thomaspaulb/f9b93850353a70e1c71207d7536abf1e to your computer and use it in GitHub Desktop.
Save thomaspaulb/f9b93850353a70e1c71207d7536abf1e to your computer and use it in GitHub Desktop.
Odoo load testing with locust
from locust import HttpUser, task, between, events
import logging
import time
import sys
```
With this locust file, you can benchmark page loads of Odoo, eg /web, /my/orders, etc.
NOTE: There is another Gist for testing RPC calls (test-rpc.py)
HOW TO USE
- save file as test-pageload.py
- modify variables
- pip install --user locust
- locust -H odoo.example.com -t 1min --headless -f test.py
```
class WebsiteUser(HttpUser):
database = "mydatabase"
login = "myuser"
password = "mypassword"
port = 443
protocol = "jsonrpcs"
wait_time = between(1, 2)
def on_start(self):
logging.info("Logging into Odoo")
session_url = f'https://{self.host}/web/session/authenticate'
data = {
'jsonrpc': '2.0',
'method': 'call',
'params': {
'db': self.database,
'login': self.login,
'password': self.password,
}
}
session_response = self.client.post(session_url, json=data)
session_data = session_response.json()
self.session_id = dict(session_response.cookies)['session_id']
logging.info("Logged in! %s", self.session_id)
@task(1)
def load_web(self):
r = self.client.get(
f'https://{self.host}/web#action=290&model=sale.order&view_type=list&cids=1&menu_id=175',
headers={"Cookie": f"session_id={self.session_id};odoo_sh_eol=1", "User-Agent": "set_useragent"},
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment