Angular http request retry causes multiple insert - mysql

I have built an angular app which calls a REST API to insert data into MySQL DB.
The logic is if the app doesn't get response within 10 seconds, it retries the same request.
At the server, there are some logic applied to calculate some values which are required to insert the data. So when the number of insert records passed by the client is more, the request cannot be completed within 10 seconds. The client aborts the request and retries the same. This causes multiple records insert.
Could someone suggest a proven solution for the same?
Thanks in advance.

Only do a retry on an error, otherwise you are getting duplicates for responses don't error (eventually giving you a response).

Related

Jmeter: How to resolve Conflict message 409 in deleting a particular id

I created a container with post Request and now i want to delete the container with container Id parameter.This is the error message i am getting .
could you tell me the reason for this conflict message in Delete HTTP Request
Since this is DELETE request/operation, 409 status code probably means you are not allowed to delete the entity. Check your user permissions and the specific entity requirements.
Most probably you have recorded your script and somewhere in generated HTTP Request samplers there is hard-coded ID of 1216 and when you're trying to replay your test with > 1 user your web application responds with HTTP 409 status code
Alternatively you're trying to update an item with again recorded hard-coded timestamp and your application refuses to do it as it's older than the current time.
So you need to revisit your HTTP Request sampler and either correlate the item ID or parameterize the timestamp using __time() function or both

How to run the jmeter thread groups one after another

The situation is next: I need to run the performance tests using jmeter. I have setup several Graphql requests, tested them and they work perfectly. The idea of the flow is next:
The user login to the platform using graphql mutation, and in response headers receives accessToken, which is valid for an hour.
The next graphql request must parce the generated token, and perform the next mutation using this token.
The idea is to test the platform with 250k requests, which takes more than 1 hour, and as you probably understand - the token is expired.
What I have done within my script:
I've created 2 thread groups. In the first, there is a Flow is Control action element, which is setup to pause duration for 3600000 msec. This means that it will run the Login request once per hour.
I'm scraping the token with JSON extractor, and parcing it using the BeanShell post-processor, by the following command:
props.put("accessToken", vars.get("accessToken"));
Second thread group has a Graphql request to perform the 250k requests to the server and uses the token value from HTTP headers:
Bearer ${__P(accessToken)}
Everything works fine, accept the fact, that I don't know how to setup the scenario, where the thread group with login will finish its run, after the second thread group will complete 250k requests.
I've tried adding the loop controller to Login, set as infinite, but the thing that once the second group will complete 250k requests - the run won't be finished, as the Login will be running forever once per hour.
Any ideas?
You can add a Loop Controller or Throughput Controller and configure them to execute these 250k requests followed by Flow Control Action Sampler configured like:
When the sampler is reached - it will tell all the threads in all thread groups to stop.
Also be informed that since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting so it makes sense to consider migration now. Storing a property once per hour with 1 thread is not something you should be worrying but for more resource intensive tasks Groovy behaves much better (for example it has built-in JSON support so you can discard the JSON Extractor)

python2.7 response to client first then process (shopify webhook)

I am building a webhook to connect Shopify with my dispatch.
Shopify Webhook sends a json request and wait for 5 seconds, if it doesn't receive 200 back, it terminate the request and try another one.
My server at the moment handle this straightaway
receive a shopify request
sorting order data from shopify
send request to dispatch server
check response from the server
response to shopify
with this sometimes it takes slightly longer than 5 seconds, so shopify send requests again while the server is updating the dispatch.
What's the best solution to fix this?
I am thinking two solutions
a. Response 200 back to shopify first then process dispatch (I am not sure how to do this with python2.7)
b. Create a database to store shopify request, so shopify request just create an order record then it will receive 200 back (which should take less than 5 seconds). With this set up crontask or celery task to update dispatch
Any suggestions?
Better to use task queues. Use celery to do time taking tasks in background. As soon as you get the response from shopify, give your task to celery so that it can run the tasks in background, then you can send the 200 response back.

Exchange Webservices (EWS) UpdateItems error 503

if i try to update more than one appointment with the Service.UpdateItems methode the server returns an 503 error.
My Code:
service.UpdateItems(appointments,folderID,ConflictResolutionMode.AutoResolve, null, SendInvitationsOrCancellationsMode.SendToNone);
Updating a single appointment with the Appointment.Update methode works.
Has anyone an idea why Service.UpdateItems does not work ?
You may be getting throttled by Exchange by trying to execute too many updates at once. Try smaller batches - of 10 items, or try spacing your requests with longer breaks between them.
As it is described here, there are three response codes which may indicate a throtting problem:
HTTP Status 503 Indicates that EWS requests are queuing with IIS. The client should delay sending additional requests until a later time.
HTTP Status 500 - Indicates an internal server error with the ErrorServerBusy error code. This indicates that the client should delay sending additional requests until a later time. The response may contain a back off hint called BackOffMilliseconds. If present, the value of BackOffMilliseconds should be used as the duration until the client resubmits a request.
HTTP Status 200 - Contains an EWS schema-based error response with an ErrorInternalServerError error code. An inner ErrorServerBusy error code may be present. This indicates that the client should delay sending additional requests until a later time.

How to Run Http Samplers in sequence order (step by step as per the ThreadGroup Order)

Behavior of my application:
HTTP Request Login
..JSON Path Extractor - Im extracting the session id
Debug Sample - Checking the session id
HTTP Request -- Im passing the session id to these requests
HTTP Request -- Im passing the session id to these requests
HTTP Request -- Im passing the session id to these requests
If I run the above script for one time Im getting the expected results above requests are passing step by step process.
If I run the above script with - Number of Threads as 5 .Then Login is hitting for 3 times other urls hitting for 2 times.
I need to run the above script one order for number of times.
I'm not seeing any regular expression extractor which you would need to pass in the session ID from one request to another. Also, if your back end uses cookies make sure to add the http cookie manager.
Here are some good JMeter getting started videos which also cover what you're trying to do:
http://blazemeter.com/blog/jmeter-tutorial-video-series