Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Refactor monkey task configuration #106

Merged
merged 6 commits into from
Jan 10, 2017

Conversation

tasomaniac
Copy link
Contributor

@tasomaniac tasomaniac commented Jan 6, 2017

This PR fixes #105

There are still things to improve how we setup our tasks but this PR is the first step to have more gradle DSL like setup for the config of the tasks.

  • Fields related to monkey are removed both from the extension and from the Monkey task class.
    • They are now encapsulated in MonkeySpec class.
  • MonkeySpec is always initialized but its internals are set using the Action class of gradle.
    • It runs a given closure against the monkey field in the extension.
    • the sample is updated to have the new way of configuring monkey.

⚠️ This is a breaking change of the public API. The users will need to wrap the monkey configuration into another closure named monkey. (Can be seen in the sample)

Depending on the decision here, we may have a follow-up PR to support to old configuration still.
Having the change documented well could also be enough. If we break the API, the upgraded version of the plugin will break the build which then can be easily fixed.

Bonus

This also works and it is great for simple configurations.

command {
  monkey.events 1000
}

as opposed to this from the sample

command {
  monkey {
    events 1000
  }
}

Said Tahsin Dane added 3 commits January 6, 2017 10:40
Define an Action in the extension to configure it.
Change the categories to have more meaningful sample
@stefanhoth stefanhoth closed this Jan 6, 2017
protected handleCommandOutput(def text) {
super.handleCommandOutput(text)
if (text.contains("Monkey aborted")) {
if (text.toLowerCase().contains("monkey aborted")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, this was kinda a hack to fail the build if the monkey is aborted.
Monkey's output sometimes starts with upper case Monkey, sometimes starts with some other message that ends with lower case monkey.
So now it will fail whatever the case.

// prefer system property over direct setting to enable commandline arguments
def getCategories() {
def systemCategories = System.properties['categories']
systemCategories ? [systemCategories] : categories
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here this also fixes a problem with command line argument support.
Basically command line support for categories was never working.

This command ./gradlew monkeyFreeBetaDebug -i -Dcategories=test would resolve into this output

[adb, -s, 02c2095608e77be5, shell, monkey, -p, com.novoda.gradle.command, -c, t, -c, e, -c, s, -c, t, -v, 1000]

It basically splits the given String into pieces.
Now only when the command line argument is provided, I am putting it into an array.

@tasomaniac tasomaniac reopened this Jan 6, 2017
Copy link
Contributor

@devisnik devisnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

this.events = events
}

void seed(seed) {
Copy link
Contributor

@devisnik devisnik Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed at all?

For lists we need the overwrite, I'm not sure about simple values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it didn't work. It looks for the method seed and errors. This magically works with the fields in Extension though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay. Fine then. 👍

// prefer system property over direct setting to enable commandline arguments
def getCategories() {
System.properties['categories'] ?: categories
public void monkey(Action<MonkeySpec> action) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public is the default, no need to specify it here.

def getCategories() {
System.properties['categories'] ?: categories
public void monkey(Action<MonkeySpec> action) {
action.execute(monkey);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ; needed. 👅

@devisnik devisnik merged commit 7ef3152 into develop Jan 10, 2017
@devisnik devisnik deleted the 105/refactor_monkey_configuration branch January 10, 2017 08:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor monkey configuration
3 participants