runner

package
v0.0.0-...-c923896 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package runner provides models and methods to interact with browsers to perform HTTP requests on websites. It is used to generate load and to delivers insights on the implication of that load.

Index

Constants

View Source
const (
	// CacheDirName is the name of the global directory used for runner caches.
	CacheDirName = "loago_runner"
)

Variables

View Source
var (
	// ErrInvalidContext is an error indicating that a given context is no runner context.
	ErrInvalidContext = errors.New("not a runner context")

	// ErrNoNetworkEventFound is an error indicating that no network event was found.
	ErrNoNetworkEventFound = errors.New("no network event for base url found")
)

Functions

func Call

func Call(ctx context.Context, url string) (time.Duration, int, string, bool, error)

Call executes an request on url using the runner context. ctx must be a valid runner context created with WithContext method of a runner instance. It returns the response time, HTTP response code, the HTTP response message an a boolean indicating if the content comes from a browser cache.

If an error occurred while performing the request an error is returned with zero values on all other return values.

Types

type ChromeRunner

type ChromeRunner struct {
	// ID of this runner.
	ID int

	// Browser cache directory path.
	CacheDir string

	// Executor interface for interacting with a browser communication library.
	Executor browser.Executor
	// contains filtered or unexported fields
}

A ChromeRunner implements the runner interface. It interacts with a chrome browser via chromedp. See: https://github.com/chromedp/chromedp

func NewChromeRunner

func NewChromeRunner(id int, e browser.Executor) *ChromeRunner

NewChromeRunner creates a new chrome runner instance.

func (*ChromeRunner) WithContext

func (r *ChromeRunner) WithContext(ctx context.Context) context.Context

WithContext derives a new context from ctx associated with both a runner and chromedp configuration. This context can be used as a context to call the Run() method. It also creates a new goroutine in background waiting for the context to be closed to clean up ressources such as the cache dir.

type FakeRunner

type FakeRunner uint

FakeRunner is a runner which fakes requests. Instead of performing real HTTP requests, it only returns fake values. This is useful for testing purposes.

func NewFakeRunner

func NewFakeRunner(id int) *FakeRunner

NewFakeRunner returns a new FakeRunner.

func (*FakeRunner) WithContext

func (r *FakeRunner) WithContext(ctx context.Context) context.Context

WithContext returns a new runner context derived from ctx.

type Runner

type Runner interface {
	WithContext(ctx context.Context) context.Context
}

Runner is an abstraction to represent objects interacting with browsers. Implementations of runner's are able to communicate with browsers (or other HTTP capable libraries).

func FromContext

func FromContext(ctx context.Context) Runner

FromContext extracts the runner instance from ctx.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL