Rishav Bhardwaj
Rishav Bhardwaj

Reputation: 77

Locust integration with product SDK is not showing stats

I'm not getting so much in documentation for sdk load testing using Locust.

from locust import HttpUser, task
import random
import string
from cnvrgv2 import Cnvrg
from cnvrgv2.modules.users.users_client import UsersClient


class CnvrgUser(HttpUser):
    def on_start(self):
      print("This is on start method")
      
      # Start an instance of of the SDK
      self.cnvrg: Cnvrg = Cnvrg(domain='***',email='***',password='***', organization='performance')
      # overwrite the internal _session attribute with the locust session
      self.cnvrg._session = self.client

    @task
    def Create_project(self):
      """User creates project"""
      print("Inside project create")
      i = 0
      while i< 10:
          project_name = 'project_name' + \
        "".join(random.choices(string.ascii_letters, k=6))
        
        # import pdb; pdb.set_trace()
        response = self.cnvrg.projects.create(project_name)
        i+=1
        # self.arch.assets.create(behaviours=["Builtin", "RecordEvidence", "Attachments"], attrs={"foo": "bar"})

As in sdk we have Session with a value {} as mentioned in doc

what is required inside this request.Sessions class in my sdk

Upvotes: 0

Views: 113

Answers (1)

Cyberwiz
Cyberwiz

Reputation: 11426

The main requirement of this approach is that you are able to replace the SDKs internally used requests.Session object with Locust's HttpSession (self.client).

First of all, does your Cnvrg object even store its session in _session? (we might need to improve the docs to clarify this requirement)

If it does, can you replace it after initializing (as is done in the example in the docs), or is it too late (because your SDK has already established session cookies etc)? If so you'd need to use a more advanced approach, maybe overriding the request method of the existing Session object.

Upvotes: 1

Related Questions