Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@task
def send_tx(self):
iroha = Iroha('admin@test')
tx = iroha.transaction([iroha.command(
'TransferAsset', src_account_id='admin@test', dest_account_id='test@test', asset_id='coin#test',
amount='0.01', description=HOSTNAME
)])
ic.sign_transaction(tx, ADMIN_PRIVATE_KEY)
self.client.send_tx_await(tx)
settings.init(
__name__,
required_data=[
'CMS_USER_EMAIL',
'TEST_FILE',
'NUM_PARALLEL_COURSES',
],
required_secrets=[
'CMS_USER_PASSWORD',
],
)
markers.install_event_markers()
class CourseImport(TaskSet):
"Course import task set -- creates course and imports tarballs."
def on_start(self):
"Setup method; log in to studio and create courses."
self.login()
for i in xrange(settings.data['NUM_PARALLEL_COURSES']):
self.create_course(i)
def login(self):
"Log in to CMS."
if settings.data.get('BASIC_AUTH_USER') is not None:
self.client.auth = (
settings.data['BASIC_AUTH_USER'],
from locust import HttpLocust, task, TaskSet
from locust.clients import HttpSession
from helpers import settings, markers
from helpers.api import LocustEdxRestApiClient
settings.init(
__name__,
required_data=['programs'],
required_secrets=['oauth'],
)
markers.install_event_markers()
class SelfInterruptingTaskSet(TaskSet):
@task(1)
def stop(self):
self.interrupt()
class CatalogTaskSet(SelfInterruptingTaskSet):
catalog_id = 1
@task(20)
def get_catalog_courses(self):
"""Retrieve all courses associated with a catalog."""
self.client.api.v1.catalogs(self.catalog_id).courses.get()
@task(10)
def list_courses_with_query(self):
"""Query the courses."""
def send_tx_await(self, transaction):
"""
Send a transaction to Iroha and wait for the final status to be reported in status stream
:param transaction: protobuf Transaction
:return: None
"""
start_time = time.time()
try:
tx_future = self._command_service_stub.Torii.future(transaction)
tx_status = 'NOT_RECEIVED'
while tx_status not in ['COMMITTED', 'REJECTED']:
for status in self.tx_status_stream(transaction):
tx_status = status[0]
except grpc.RpcError as e:
total_time = int((time.time() - start_time) * 1000)
events.request_failure.fire(request_type="grpc", name='send_tx_await', response_time=total_time, exception=e)
else:
total_time = int((time.time() - start_time) * 1000)
events.request_success.fire(request_type="grpc", name='send_tx_await', response_time=total_time, response_length=0)
# In this example, I've hardcoded response_length=0. If we would want the response length to be
def waitForWorkspaceToStop(self, id):
timeout_in_seconds = 60 if os.getenv("STOP_HARD_FAILURE_TIMEOUT") == None else int(os.getenv("STOP_HARD_FAILURE_TIMEOUT"))
soft_timeout_seconds = 5 if os.getenv("STOP_SOFT_FAILURE_TIMEOUT") == None else int(os.getenv("STOP_SOFT_FAILURE_TIMEOUT"))
isSoftFailure = False
workspace_status = self.getWorkspaceStatus(id)
while workspace_status != "STOPPED":
now = time.time()
elapsed_time = int(now - self.start)
if elapsed_time > soft_timeout_seconds and isSoftFailure == False:
self.log("Workspace stopping on "+self.clusterName+" failed with soft failure.")
os.system(self.soft_stop_failure_cmd+" -o 1 >/dev/null 2>&1")
isSoftFailure = True
if elapsed_time > timeout_in_seconds:
events.request_failure.fire(request_type="REPEATED_GET",
name="stopWorkspace_"+self.clusterName,
response_time=self._tick_timer(),
exception="Workspace wasn't able to stop in "
+ str(elapsed_time)
+ " seconds.")
self.log("Workspace " + self.id + " wasn't able to stop in "
+ str(elapsed_time) + " seconds.")
os.system(self.hard_stop_failure_cmd+" -o 1 >/dev/null 2>&1")
return
self.log("Workspace id " + id + " is still not in state STOPPED ["
+ workspace_status +"] {" + str(elapsed_time) + " of " + str(timeout_in_seconds) + "}")
self.wait()
workspace_status = self.getWorkspaceStatus(id)
self.log("Workspace id " + id + " is STOPPED")
events.request_success.fire(request_type="REPEATED_GET",
name="stopWorkspace_"+self.clusterName,
print("\n["+self.clusterName+"] Running workspace start test "+str(self.cycles + 1)+" of "+str(self.cyclesMax)+"\n")
self.log("Checking if there are some removing pods before creating and running new workspace.")
self.waitUntilDeletingIsDone()
self.id = self.createWorkspace()
self.wait()
self._reset_timer()
self.startWorkspace()
self.wait()
self.waitForWorkspaceToStart()
self._reset_timer()
self.stopWorkspaceSelf()
self.waitForWorkspaceToStopSelf()
self.wait()
self.deleteWorkspaceSelf()
if (self.cycles == (self.cyclesMax - 1)):
raise StopLocust("Tests finished, unable to set Locust to run set number of times (https://github.com/locustio/locust/pull/656), issuing hard-stop.")
self.cycles += 1
from locust import HttpUser, TaskSet, task
class RegistredUser(HttpUser):
min_wait = 5000
max_wait = 9000
@task
class RandomStresstest(TaskSet):
@task(2)
def list(self):
self.client.get('/random-list')
@task(1)
def insert_random_value(self):
self.client.put('/random', {'lower': 0, 'upper': 10000})
from random import randrange
from locust import HttpUser, TaskSet, task
class RegistredUser(HttpUser):
min_wait = 5000
max_wait = 9000
@task
class CrudStresstest(TaskSet):
def __get_random_user(self):
userid = str(randrange(0, 10000))
username = 'testuser_{0}'.format(userid)
email = 'some-email{0}@yahoo.com'.format(userid)
return userid, username, email
@task(1)
def add_user(self):
user_data = self.__get_random_user()
user = {
@task(50)
def vote_on_comment(self):
"""
Vote on a comment_response
Calls made:
GET_thread_list
GET_comment_list
PATCH_comment
"""
data = {"voted": random.choice(["true", "false"])}
name = "vote_on_comment" if self.verbose else "PATCH_comment"
self.patch_comment(
comment_id=self._get_comment_id(),
data=data,
name=name
)
@task
def search_notes(self):
"""
Search notes for random text.
"""
path = '/api/v1/search/'
self.get(
path,
{
'user': self._anonymous_user_id,
'course_id': self.course_id,
'text': ' '.join(pick_some(
NOTES_TEXT,
settings.data['NUM_SEARCH_TERMS'],
)),
'highlight': True,
'highlight_tag': HIGHLIGHT_TAG,