Monthly Archives: July 2013

Throttle bandwidth on mac useful for ios simulator

If you want to simulate non strong wifi connections for the iOs simulator on Xcode you will need to throttle your bandwitdth.

There is speed limit but it does not provide a true representation of how different problems affecting slow speeds work.

Apple does have a tool that does not come bundled with the XCode tools.

Hardware IO Tools for Xcode – Late July 2012 was the version I downloaded.

Inside the pkg There is a preferences panel that you can install called

Network Link Conditioner

that you can simulate Edge 3g with packet loss along with many other situations.

Advertisements

HTTPBuilder and post

Posting using HTTPBuilder to post I have only gotten to work using the request method.

HttpBuilder post docs

Here is a code snippet that I use to that works sending JSON to a server method that returns JSON.


def http = new HTTPBuilder("http://foo.com")

http.request(Method.POST){
  uri.path = "/do/something"
  send groovyx.net.http.ContentType.URLENC,
       [name: "admin", action: "save"] response.success = {resp, json ->
    println "status $resp.status"
    println "status info"
    resp.properties { name, value ->
      println "$name : $value"
    }
    println "json"
    json.properties { name, value ->
      println "$name : $value"
    }
 }
 response.failure = {resp, json ->
   println "status $resp.status"
   println "response info"
   resp.properties { name, value ->
     println "$name : $value"
   }
   println "json"
   json.properties { name, value ->
     println "$name : $value"
   }
 }
}

 

Unit testing angularjs with $http

Angularjs unit testing with $http.

How it all hangs together

When calling external servers to get or push data you can use the $http from angular.  $http has a set of methods like Get, Post and Put like you would expect.

$http callback methods.

It treats the call much like a ajax call where it has a .success method and a .error method which it returns to depending on if the call success or failure.

Scoping of parameters and .success() and .errror()

You can interact with the $scope or $rootScope to set or change data.  The scoping of the .success() and .error() means you cannot use a method level parameter and expect the value to be assigned before the the method ends.  It can go out of scope before it is guaranteed to be set.

Continue reading

angularjs e2e test with $http and out of memory exception

My experience with $httpBackend with e2e tests and out of memory exceptions.

$httpBackend and out of memory exceptions

I am running yadda with casperjs to do functional end to end testing.

I was doing a simple $http request that would expect some JSON back.  I was getting through 2.5gb of ram before my Casperjs test would fall over with out of memory exception and Phantomjs telling me how to report this bug.  I followed the instructions to get an error report for Phantomjs and it was not giving me any useful information for a bug report, so it was something in my code that was the problem.

What I figured out:

Returning invalid JSON and making lots calls to the $httpBackend in quick succession then I experienced my tests falling over very quickly with out of memory exceptions.  It also slows down the tests as the memory does not get released very quickly.

If you make lots of calls to $httpBackend full stop then it tends to chew through lots of memory.  Use it sparingly and have your code against calling it too frequently as it is very expensive.

There is caching available for on $http requests but I have not used it yet. $http