Code Monkey home page Code Monkey logo

odoolocust's Introduction

OdooLocust

An Odoo load testing solution, using odoolib and Locust. Locust API changed a bit, and OdooLocust follow this change.

Links

HowTo

To load test Odoo, you create tests like you'll have done it with Locust:

from locust import task, between
from OdooLocust.OdooLocustUser import OdooLocustUser


class Seller(OdooLocustUser):
    wait_time = between(0.1, 10)
    database = "test_db"
    login = "admin"
    password = "secret_password"
    port = 443
    protocol = "jsonrpcs"

    @task(10)
    def read_partners(self):
        cust_model = self.client.get_model('res.partner')
        cust_ids = cust_model.search([])
        prtns = cust_model.read(cust_ids)

    @task(5)
    def read_products(self):
        prod_model = self.client.get_model('product.product')
        ids = prod_model.search([])
        prods = prod_model.read(ids)

    @task(20)
    def create_so(self):
        prod_model = self.client.get_model('product.product')
        cust_model = self.client.get_model('res.partner')
        so_model = self.client.get_model('sale.order')

        cust_id = cust_model.search([('name', 'ilike', 'fletch')])[0]
        prod_ids = prod_model.search([('name', 'ilike', 'ipad')])

        order_id = so_model.create({
            'partner_id': cust_id,
            'order_line': [(0, 0, {'product_id': prod_ids[0],
                                   'product_uom_qty': 1}),
                           (0, 0, {'product_id': prod_ids[1],
                                   'product_uom_qty': 2}),
                          ]
        })
        so_model.action_button_confirm([order_id])

The host on which run the load is defined in locust.conf file, either in your project folder or home folder, as explained in Locust doc: https://docs.locust.io/en/stable/configuration.html#configuration-file

host=localhost
users = 100
spawn-rate = 10

then you run your locust tests the usual way:

locust -f my_file.py

Generic test

This version is shipped with a generic TaskSet task, OdooTaskSet, and a TaskSet which randomly click on menu items, OdooGenericTaskSet. To use this version, create this simple test file:

from OdooLocust.OdooLocustUser import OdooLocustUser
from locust import task, between
from OdooLocust import OdooTaskSet


class GenericTest(OdooLocustUser):
    wait_time = between(0.1, 1)
    database = "my_db"
    login = "admin"
    password = "secure_password"
    port = 443
    protocol = "jsonrpcs"

    @task(10)
    def read_partners(self):
        cust_model = self.client.get_model('res.partner')
        cust_ids = cust_model.search([], limit=80)
        prtns = cust_model.read(cust_ids, ['name'])

    tasks = [OdooTaskSet.OdooGenericTaskSet]

and you finally run your locust tests the usual way:

locust -f my_file.py

CRM test

This version is shipped with some CRM tests.

# -*- coding: utf-8 -*-
from OdooLocust import OdooLocustUser, crm

class OdooCom(OdooLocustUser.OdooLocustUser):
    host = "erp.mycompany.com"
    database = "my_db"
    login = "admin"
    password = "secure_password"
    port = 443
    protocol = "jsonrpcs"

    tasks = {crm.partner.ResPartner: 1, crm.lead.CrmLead: 2, crm.quotation.SaleOrder: 1}

Test with workers

As Locust use greenlet, you're using one core of your computer. If this is a limiting factor, it's possible to use multiple workers. It's also possible to run a headless test, to automate it. This sh file run a headless test, without asking host, users, ... using an Odoo load test file called load_odoo.py:

#!/bin/bash
if [ -z "$3" ]
  then
      echo "No argument supplied"
      echo "start_workers.sh nbr_workers concurrency time"
      exit 1
fi
x=1
while [ $x -le $1 ]
do
  locust -f load_odoo.py --worker --only-summary > /dev/null 2>&1 &
  x=$(( $x + 1 ))
done
locust -f load_odoo.py --headless --users $2 --spawn-rate $2 --run-time $3m --master --expect-workers=$1

odoolocust's People

Contributors

celm1990 avatar dependabot[bot] avatar lucaslefevre avatar nseinlet avatar rafnixg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

odoolocust's Issues

Odoolocust : Locustio --> Locust (moved)

Impacted versions: last version of OdooLocust

Steps to reproduce: pip install odoolocust

Current behavior:

Requirement already satisfied: MarkupSafe>=0.23 in ./venv/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask>=1.1.2->locust->odoolocust) (1.1.1)
Using legacy setup.py install for odoolocust, since package 'wheel' is not installed.
Using legacy setup.py install for locustio, since package 'wheel' is not installed.
Installing collected packages: locustio, odoolocust
    Running setup.py install for locustio ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/vincentcoffin/Projects/Config/load-testing/fppm-load-testing/venv/bin/python3.7 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/t_/y5vn42xj06q1_114w4c8m5r80000gn/T/pip-install-_4iz8zsj/locustio/setup.py'"'"'; __file__='"'"'/private/var/folders/t_/y5vn42xj06q1_114w4c8m5r80000gn/T/pip-install-_4iz8zsj/locustio/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/t_/y5vn42xj06q1_114w4c8m5r80000gn/T/pip-record-vqtr2ov7/install-record.txt --single-version-externally-managed --compile --install-headers /Users/vincentcoffin/Projects/Config/load-testing/fppm-load-testing/venv/include/site/python3.7/locustio
         cwd: /private/var/folders/t_/y5vn42xj06q1_114w4c8m5r80000gn/T/pip-install-_4iz8zsj/locustio/
    Complete output (4 lines):
    running install
    
    **** Locust package has moved from 'locustio' to 'locust'. Please update your reference (or pin your version to 0.14.6 if you dont want to update to 1.0) ****

Expected behavior:

It should install locust instead of locustio (moved)

Video/Screenshot link (optional):

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.