Unit testing and getting consistent results


#1

As good developers, we’re testing our connectivity, get, delete and post requests with HubSpot to ensure that our methods are working without issue. However, I am finding inconsistent results with tests passing sometimes, and the same tests, failing at other times. We’re currently hitting the regular HubSpot endpoints but I was wondering if there is a better HubSpot server to hit for our tests which are automatically run whenever a new build is pushed.

Thanks for any suggestions.


#2

HI @Paul

Do you have any examples of the requests you’re seeing this with? Are your tests getting actual error responses in some cases or just unexpected data in the response?


#3

Here is an example of it failing and of it working:

16:33:53.7774 INFO::
HubSpot POST request https://api.hubapi.com/contacts/v1/contact?hapikey=xxx with {“properties”:[{“property”:“email”,“value”:“tbone4@xxx.com”},{“property”:“firstname”,“value”:“Tee”},{“property”:“lastname”,“value”:“Bone”},{“property”:“company”,“value”:“Bones Shirts”},{“property”:“phone”,“value”:“000 000-0000”}]}

16:34:03.7984 ERROR::
System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at xxxHubSpotServices.HubSpotPostRequest(String url, String jsonPostData)

09:35:09.7260 INFO::
HubSpot POST request https://api.hubapi.com/contacts/v1/contact?hapikey=xxx with {“properties”:[{“property”:“email”,“value”:“tbone4@xxx.com”},{“property”:“firstname”,“value”:“Tee”},{“property”:“lastname”,“value”:“Bone”},{“property”:“company”,“value”:“Bones Shirts”},{“property”:“phone”,“value”:“000 000-0000”}]}

09:35:10.3895 INFO::
Received OK response


#4

Do you know when you saw that timeout error? Do you know if you received any response at all from HubSpot or did the endpoint take more than 10 seconds to respond?


#5

Those two requests were made from two different servers hence the date/time difference but they were performed within two minutes of each other. I have got the timeout setting for 10 seconds so not sure if I would ever have received a reply. I’ll comment out the timeout value, let it run, and see if a response comes back at all.


#6

David,

Looks like it timed out after 100 seconds (default?).

21:25:51.0968 INFO::
HubSpot POST request https://api.hubapi.com/contacts/v1/contact?hapikey=xxx with {“properties”:[{“property”:“email”,“value”:“tbone4@xxx.com”},{“property”:“firstname”,“value”:“Tee”},{“property”:“lastname”,“value”:“Bone”},{“property”:“company”,“value”:“Bones Shirts”},{“property”:“phone”,“value”:“000 000-0000”}]}

21:27:31.1178 ERROR::
System.Net.WebException: The operation has timed out
at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context)
at System.Net.HttpWebRequest.GetRequestStream()
at xxxHubSpotServices.HubSpotPostRequest(String url, String jsonPostData)


#7

Are you seeing that issue with other endpoints? Do you have a way to test that server’s connectivity to api.hubapi.com outside of that code (via RDC or something like that)? Our load balancers normally return a 504 much sooner than 100 seconds, so this may be a more general network problem and not something specific to the API itself.


#8

David, I have three POST tests on a particular test project. The first creates a new contact. The second creates a new contact, then tries to create another contact using the same address and we check for a 409 response. The third creates a new contact and then tries to delete the contact. It is the third test that fails. All three tests use different email addresses for the contacts they are creating, btw.