artilleryio / artillery-core

artillery-core - deprecated
Mozilla Public License 2.0
29 stars 104 forks source link

Remember cookies for following requests in scenario spec #1

Closed gajjargaurav closed 9 years ago

gajjargaurav commented 9 years ago

In a scenario where a user needs to log in (e.g. a POST request) and go to a home( e.g. a GET request), where the home page requires the cookie set during the log in process to load the page correctly. e.g.

 {
  "config": {
    "target": "http://localhost:8080",
    "phases": [{
      "duration": 10,
      "arrivalRate": 10
    }],
   "jar": true // or false for all the scenarios by default which can be overridden at request level under scenarios
  },
  "scenarios": [{
    "flow": [{
      "post": {
        "url": "/login",
        "headers": {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        "jar": true, // to start persisting cookies 
        "body": "username=awsomeuser&password=password"
      }
    },{
      "think": 1
    }, {
      "get": {
        "url": "/home",
        "headers":{
          "Content-Type": "application/x-www-form-urlencoded"
        },
        "jar": false // to stop persisting cookies
      }
    }]
  }]
} 
hassy commented 9 years ago

Thanks @gajjargaurav! :star2: Perhaps the jar should be enabled by default, with the option to disable it on per-scenario basis?

gajjargaurav commented 9 years ago

@hassy could do that. However request by default doesn't set it. If we set up that as default we are making an assumption that users would want that most of the time. I don't see that to be the case.

hassy commented 9 years ago

@gajjargaurav Yes, perhaps, although if the server doesn't send any cookies, there would be no performance overhead - and if it does, then the user probably wants these cookies to be sent on subsequent requests. Either way, I think cookies should be a global option (set in config.defaults), and it should be possible to set it on individual scenarios. The implementation should also make sure that there's a different cookie jar for every running scenario, rather than a global request one.

gajjargaurav commented 9 years ago

Yes, that sounds like a plan. Thanks

gajjargaurav commented 9 years ago

@hassy , I've done a quick fix for now if that is acceptable. I would like to extend that to actually pass in cookies to set to in the cookie jar.

hassy commented 9 years ago

@gajjargaurav It does not seem to work as described in the issue, i.e. cookie support should be enabled by default.

I added a basic test case in this commit: https://github.com/artilleryio/minigun-core/commit/e7ac291d0b8a4ebd09c228b3206f069fcadd19f0 - this makes sure that cookies are enabled by default - will you have a chance to rewrite the PR so that this test passes? If not, I'm happy to do it.

gajjargaurav commented 9 years ago

@hassy , I will look into it during the weekend and update the PR.

hassy commented 9 years ago

@gajjargaurav Awesome, thanks! :)

gajjargaurav commented 9 years ago

@hassy I did get it working locally for global request object, however I am having issues doing with a separate jar for each scenario