Skip to content

Instantly share code, notes, and snippets.

@ghenzler
Last active July 4, 2021 03:50
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ghenzler/e4a924bc29a119a96d5abe1fa99122be to your computer and use it in GitHub Desktop.

Breaklets

The Idea

Breaklets are a way to check limits of a platform/aspect/tool. Breaklets

  • ... iteratively make things worse
  • ... run until either
    • a threshold is reached
    • R.I.P
    • stopped "while in panic" (just create a file "panic" in current working dir)
  • ... are scripted (quick to write/change)

The below examples are made for AEM using the the AEM Groovy Console, but the approach of breaklets can be used in any language/platform/program.

Usage

Examples

The quickest way is to modify some of the existing examples:

Basic Structure

A simple breaklet looks as follows:

//-------------------------------------
// Breaklet Config
//-------------------------------------
def breakForDurationInSec = 60

// insert other vars to be used by closure below

//-------------------------------------
// Breaklet
//-------------------------------------

new Breaklet(this, breakForDurationInSec, sessionUser, sessionPassword).run { breaklet, currentIt, itSession  ->

	// this is run in iterations
	//    'breaklet' makes certain breaklet operations available in the closure (e.g. logOpFinished)
	//    'currentIt' contains the iteration number
	//    'itSession' contains a session that is created explicitly for this iteration (using sessionUser & sessionPassword
	
	// do something here with the session
	breaklet.logOpFinished("My operation finished") // will show in the log and a csv files with timings is automatically created
	
	// once breakForDurationInSec is reached, the iteration will break
	
}

// include the contents of https://gist.github.com/ghenzler/58ce57794ba9b5a60f2a2e60160be747 below here

Useful operations

NOTE: This is not really an API, it can be changed at any time. Also feel free to suggest improvements to breaklet-base.groovy

Class Breaklet

  • logMsg("message") - will log a regular message
  • breaklet.logOpFinished("message",...) - logs a message with timinig (also creates a timings CSV in current working dir)
  • breaklet.performRequest(String requestPath, ...) - to run a request (uses simple UrlConnection)
  • breaklet.runInBrowser("node.js script") - will run the given script with chrome headless/puppeteer
  • breaklet.registerResourceChangeListener(paths) and breaklet. waitForResourceChangedEvents(long minimumExpectedChanges, ...) to wait for resource changed events

JS Functions available in breaklet.runInBrowser()

  • await waitForCrxdeNodeWithName(page, nodename) - waits for a nodename in CRXDE
  • await clickOnIconOfCrxdeNode(page, nodename) - clicks on the icon of a node in CRXDE to expand/collapse it
  • await waitForXPath(xpath) - waits for DOM XPath query (useful to wait for texts that cannot be queried easily with CSS selectors
  • await waitForAndClick(page, selector) - will wait for selector and then click
  • await createScreenshot(page, nameSuffix) - will create a screenshot with a certain name suffix
  • await sleep(ms) - will sleep ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment