Documentation
¶
Overview ¶
Package coordinatetest provides generic functional tests for the Coordinate interface. A typical backend test module needs to wrap Suite to create its backend:
package mybackend import ( "testing" "github.com/diffeo/go-coordinate/coordinate/coordinatetest" "github.com/stretchr/testify/suite" ) // Suite is the per-backend generic test suite. type Suite struct{ coordinatetest.Suite } // SetupSuite does global setup for the test suite. func (s *Suite) SetupSuite() { s.Suite.SetupSuite() s.Coordinate = NewWithClock(s.Clock) } // TestCoordinate runs the Coordinate generic tests. func TestCoordinate(t *testing.T) { suite.Run(t, &Suite{}) }
Index ¶
- type HasData
- type SimpleTestSetup
- func (sts *SimpleTestSetup) AddWorkUnit(name string) (coordinate.WorkUnit, error)
- func (sts *SimpleTestSetup) CheckUnitStatus(s *Suite, status coordinate.WorkUnitStatus)
- func (sts *SimpleTestSetup) CheckWorkUnitOrder(s *Suite, unitNames ...string)
- func (sts *SimpleTestSetup) MakeWorkUnits() (map[string]coordinate.WorkUnit, error)
- func (sts *SimpleTestSetup) RequestNoAttempts(s *Suite)
- func (sts *SimpleTestSetup) RequestOneAttempt(s *Suite) coordinate.Attempt
- func (sts *SimpleTestSetup) SetUp(s *Suite)
- func (sts *SimpleTestSetup) TearDown(s *Suite)
- type Suite
- func (s *Suite) AttemptMatches(expected, actual coordinate.Attempt) bool
- func (s *Suite) AttemptStatus(expected coordinate.AttemptStatus, attempt coordinate.Attempt) bool
- func (s *Suite) DataEmpty(obj HasData) bool
- func (s *Suite) DataMatches(obj HasData, expected map[string]interface{}) bool
- func (s *Suite) SetupSuite()
- func (s *Suite) TestAddSameUnit()
- func (s *Suite) TestAddWorkUnitBleedover()
- func (s *Suite) TestAttemptExpiration()
- func (s *Suite) TestAttemptFractionalStart()
- func (s *Suite) TestAttemptGone()
- func (s *Suite) TestAttemptLifetime()
- func (s *Suite) TestAttemptMetadata()
- func (s *Suite) TestByRuntime()
- func (s *Suite) TestChainingDuplicate()
- func (s *Suite) TestChainingExpiry()
- func (s *Suite) TestChainingMixed()
- func (s *Suite) TestChainingTwoStep()
- func (s *Suite) TestChangeSpecData()
- func (s *Suite) TestConcurrentExecution()
- func (s *Suite) TestContinuous()
- func (s *Suite) TestContinuousInterval()
- func (s *Suite) TestCountWorkUnitStatus()
- func (s *Suite) TestDataEmptyList()
- func (s *Suite) TestDeactivateChild()
- func (s *Suite) TestDefaultMeta()
- func (s *Suite) TestDelayedOutput()
- func (s *Suite) TestDeleteWorkUnits()
- func (s *Suite) TestMaxRetries()
- func (s *Suite) TestMaxRetriesMulti()
- func (s *Suite) TestMaxRetriesMultiBatch()
- func (s *Suite) TestMaxRunning()
- func (s *Suite) TestMetaContinuous()
- func (s *Suite) TestMetaCounts()
- func (s *Suite) TestNamespaceTrivial()
- func (s *Suite) TestNamespaces()
- func (s *Suite) TestNiceWeight()
- func (s *Suite) TestNotBeforeAttempt()
- func (s *Suite) TestNotBeforeDelayedStatus()
- func (s *Suite) TestNotBeforePriority()
- func (s *Suite) TestOneDayInterval()
- func (s *Suite) TestPrefilledMeta()
- func (s *Suite) TestRecreateWorkUnits()
- func (s *Suite) TestRequestSpecificSpec()
- func (s *Suite) TestRetryDelay()
- func (s *Suite) TestSetDataSetsMeta()
- func (s *Suite) TestSetMeta()
- func (s *Suite) TestSpecCreateDestroy()
- func (s *Suite) TestSpecDeletedGone()
- func (s *Suite) TestSpecErrors()
- func (s *Suite) TestSpecInNamespaceGone()
- func (s *Suite) TestSummarize()
- func (s *Suite) TestTrivialWorkUnitFlow()
- func (s *Suite) TestTwoWorkSpecsBasic()
- func (s *Suite) TestUnitDeletedGone()
- func (s *Suite) TestUnitSpecDeletedGone()
- func (s *Suite) TestWorkUnitChaining()
- func (s *Suite) TestWorkUnitData()
- func (s *Suite) TestWorkUnitOrder()
- func (s *Suite) TestWorkUnitPriorityCtor()
- func (s *Suite) TestWorkUnitPrioritySet()
- func (s *Suite) TestWorkUnitQueries()
- func (s *Suite) TestWorkerAdoption()
- func (s *Suite) TestWorkerAncestry()
- func (s *Suite) TestWorkerAttempts()
- func (s *Suite) TestWorkerMetadata()
- func (s *Suite) UnitHasPriority(unit coordinate.WorkUnit, priority float64) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HasData ¶
HasData describes attempts, workers, and work units that can return their own data (probably).
type SimpleTestSetup ¶
type SimpleTestSetup struct { // NamespaceName, if non-empty, requests a Namespace be // created with this name. It is frequently the name of the // test. NamespaceName string // Namespace is the namespace to use. If this is nil then // a new namespace will be created from NamespaceName, even // if that is empty. Namespace coordinate.Namespace // WorkerName, if non-empty, requests a Worker be created // with this name. WorkerName string // Worker is set on output. Worker coordinate.Worker // WorkSpecName, if non-empty, sets the name of the work spec. WorkSpecName string // WorkSpecData, if non-empty, provides additional data for // the work spec. If WorkSpecName is also set it will overwrite // this name. WorkSpecData map[string]interface{} // WorkSpec is set on output. WorkSpec coordinate.WorkSpec // WorkUnitName, if non-empty, gives the name of a work unit. WorkUnitName string // WorkUnitData, if non-empty, provides the corresponding // work unit data. WorkUnitData map[string]interface{} // WorkUnitMeta gives additional options for the work unit. WorkUnitMeta coordinate.WorkUnitMeta // WorkUnit is set on output. WorkUnit coordinate.WorkUnit }
SimpleTestSetup defines parameters for common tests, that use a small number of workers, work specs, etc.
func (*SimpleTestSetup) AddWorkUnit ¶
func (sts *SimpleTestSetup) AddWorkUnit(name string) (coordinate.WorkUnit, error)
AddWorkUnit adds a single work unit to the work spec with default (empty) data and metadata.
func (*SimpleTestSetup) CheckUnitStatus ¶
func (sts *SimpleTestSetup) CheckUnitStatus(s *Suite, status coordinate.WorkUnitStatus)
CheckUnitStatus checks that the test's work unit's status matches an expected value.
func (*SimpleTestSetup) CheckWorkUnitOrder ¶
func (sts *SimpleTestSetup) CheckWorkUnitOrder(s *Suite, unitNames ...string)
CheckWorkUnitOrder requests every possible attempt, one at a time, virtually pausing 5 seconds between each. It checks that the resulting ordering matches the provided order of work unit names.
func (*SimpleTestSetup) MakeWorkUnits ¶
func (sts *SimpleTestSetup) MakeWorkUnits() (map[string]coordinate.WorkUnit, error)
MakeWorkUnits creates a handful of work units within a work spec. These have keys "available", "pending", "finished", "failed", "expired", and "retryable", and wind up in the corresponding states.
func (*SimpleTestSetup) RequestNoAttempts ¶
func (sts *SimpleTestSetup) RequestNoAttempts(s *Suite)
RequestNoAttempts requests attempts and asserts that nothing was returned. It does not fail the test if something does come back.
func (*SimpleTestSetup) RequestOneAttempt ¶
func (sts *SimpleTestSetup) RequestOneAttempt(s *Suite) coordinate.Attempt
RequestOneAttempt gets a single attempt from the test's worker, or fails the test immediately if not exactly one attempt was returned.
func (*SimpleTestSetup) SetUp ¶
func (sts *SimpleTestSetup) SetUp(s *Suite)
SetUp populates the output fields of the test setup, or fails using t.FailNow().
func (*SimpleTestSetup) TearDown ¶
func (sts *SimpleTestSetup) TearDown(s *Suite)
TearDown destroys the namespace and all other resources created in SetUp.
type Suite ¶
type Suite struct { suite.Suite // Clock contains the alternate time source to be used in tests. It // is pre-initialized to a mock clock. Clock *clock.Mock // Coordinate contains the top-level interface to the backend under // test. It is set by importing packages. Coordinate coordinate.Coordinate }
Suite is the generic Coordinate backend test suite.
func (*Suite) AttemptMatches ¶
func (s *Suite) AttemptMatches(expected, actual coordinate.Attempt) bool
AttemptMatches checks that two attempts are attempting the same thing.
func (*Suite) AttemptStatus ¶
func (s *Suite) AttemptStatus( expected coordinate.AttemptStatus, attempt coordinate.Attempt, ) bool
AttemptStatus checks that an attempt has an expected status.
func (*Suite) DataMatches ¶
DataMatches checks that an object's data matches an expected value.
func (*Suite) SetupSuite ¶
func (s *Suite) SetupSuite()
SetupSuite does one-time initialization for the test suite.
func (*Suite) TestAddSameUnit ¶
func (s *Suite) TestAddSameUnit()
TestAddSameUnit creates the same work unit many times in parallel and checks for errors.
func (*Suite) TestAddWorkUnitBleedover ¶
func (s *Suite) TestAddWorkUnitBleedover()
TestAddWorkUnitBleedover validates a bug in the postgres backend where adding a duplicate work unit in one work spec would modify similarly-named work units' data in all work specs.
func (*Suite) TestAttemptExpiration ¶
func (s *Suite) TestAttemptExpiration()
TestAttemptExpiration validates that an attempt's status will switch (on its own) to "expired" after a timeout.
func (*Suite) TestAttemptFractionalStart ¶
func (s *Suite) TestAttemptFractionalStart()
TestAttemptFractionalStart verifies that an attempt that starts at a non-integral time (as most of them are) can find itself. This is a regression test for a specific issue in restclient.
func (*Suite) TestAttemptGone ¶
func (s *Suite) TestAttemptGone()
TestAttemptGone verifies that, if a work unit is deleted, its attempts return ErrGone for things.
func (*Suite) TestAttemptLifetime ¶
func (s *Suite) TestAttemptLifetime()
TestAttemptLifetime validates a basic attempt lifetime.
func (*Suite) TestAttemptMetadata ¶
func (s *Suite) TestAttemptMetadata()
TestAttemptMetadata validates the various bits of data associated with a single attempt.
func (*Suite) TestByRuntime ¶
func (s *Suite) TestByRuntime()
TestByRuntime creates two work specs with different runtimes, and validates that requests that want a specific runtime get it.
func (*Suite) TestChainingDuplicate ¶
func (s *Suite) TestChainingDuplicate()
TestChainingDuplicate tests that work unit chaining still works even when the same output work unit is generated twice (it should get retried).
func (*Suite) TestChainingExpiry ¶
func (s *Suite) TestChainingExpiry()
TestChainingExpiry tests that, if an attempt finishes but is no longer the active attempt, then its successor work units will not be created.
func (*Suite) TestChainingMixed ¶
func (s *Suite) TestChainingMixed()
TestChainingMixed uses a combination of strings and tuples in its "output" data.
func (*Suite) TestChainingTwoStep ¶
func (s *Suite) TestChainingTwoStep()
TestChainingTwoStep separately renews an attempt to insert an output key, then finishes the work unit; it should still chain.
func (*Suite) TestChangeSpecData ¶
func (s *Suite) TestChangeSpecData()
TestChangeSpecData tests WorkSpec.SetData().
func (*Suite) TestConcurrentExecution ¶
func (s *Suite) TestConcurrentExecution()
TestConcurrentExecution creates 100 work units and runs them concurrently, testing that each gets executed only once.
func (*Suite) TestContinuous ¶
func (s *Suite) TestContinuous()
TestContinuous creates a continuous work spec but no work units for it. Requesting attempts should create a new work unit for it.
func (*Suite) TestContinuousInterval ¶
func (s *Suite) TestContinuousInterval()
TestContinuousInterval verifies the operation of a continuous work spec that has a minimum respawn frequency.
func (*Suite) TestCountWorkUnitStatus ¶
func (s *Suite) TestCountWorkUnitStatus()
TestCountWorkUnitStatus does simple validation on the CountWorkUnitStatus call.
func (*Suite) TestDataEmptyList ¶
func (s *Suite) TestDataEmptyList()
TestDataEmptyList verifies that an empty list gets preserved in the work spec data, and not remapped to nil.
func (*Suite) TestDeactivateChild ¶
func (s *Suite) TestDeactivateChild()
TestDeactivateChild tests that deactivating a worker with a parent works successfully. This is a regression test for a specific issue in the REST API.
func (*Suite) TestDefaultMeta ¶
func (s *Suite) TestDefaultMeta()
TestDefaultMeta tests that WorkSpec.Meta gets the correct defaults, which in a couple of cases are not zero values.
func (*Suite) TestDelayedOutput ¶
func (s *Suite) TestDelayedOutput()
TestDelayedOutput tests that the output of chained work specs can be delayed.
func (*Suite) TestDeleteWorkUnits ¶
func (s *Suite) TestDeleteWorkUnits()
TestDeleteWorkUnits is a smaller set of tests for WorkSpec.DeleteWorkUnits(), on the assumption that a fair amount of code will typically be shared with GetWorkUnits() and because it is intrinsically a mutating operation.
func (*Suite) TestMaxRetries ¶
func (s *Suite) TestMaxRetries()
TestMaxRetries is a simple test for the max_retries work spec option.
func (*Suite) TestMaxRetriesMulti ¶
func (s *Suite) TestMaxRetriesMulti()
TestMaxRetriesMulti tests both setting max_retries and max_getwork.
func (*Suite) TestMaxRetriesMultiBatch ¶
func (s *Suite) TestMaxRetriesMultiBatch()
TestMaxRetriesMultiBatch is like TestMaxRetriesMulti, but has an entire batch go over the retry limit.
func (*Suite) TestMaxRunning ¶
func (s *Suite) TestMaxRunning()
TestMaxRunning tests that setting the max_running limit on a work spec does result in work coming back.
func (*Suite) TestMetaContinuous ¶
func (s *Suite) TestMetaContinuous()
TestMetaContinuous specifically checks that you cannot enable the "continuous" flag on non-continuous work specs.
func (*Suite) TestMetaCounts ¶
func (s *Suite) TestMetaCounts()
TestMetaCounts does basic tests on the "available" and "pending" counts.
func (*Suite) TestNamespaceTrivial ¶
func (s *Suite) TestNamespaceTrivial()
TestNamespaceTrivial checks that a namespace's name matches the test name.
func (*Suite) TestNamespaces ¶
func (s *Suite) TestNamespaces()
TestNamespaces does some basic tests on the namespace list call. If this is run against a shared server, it may not be possible to assert that no namespaces beyond the specific test namespace exist, so this only verifies that the requested namespace is present.
func (*Suite) TestNiceWeight ¶
func (s *Suite) TestNiceWeight()
TestNiceWeight tests the "weight = 20-nice" rule.
func (*Suite) TestNotBeforeAttempt ¶
func (s *Suite) TestNotBeforeAttempt()
TestNotBeforeAttempt verifies that, if a work unit is created with a "not before" time, it is not returned as an attempt.
func (*Suite) TestNotBeforeDelayedStatus ¶
func (s *Suite) TestNotBeforeDelayedStatus()
TestNotBeforeDelayedStatus verifies that, if a work unit is created with a "not before" time, its status is returned as DelayedUnit.
func (*Suite) TestNotBeforePriority ¶
func (s *Suite) TestNotBeforePriority()
TestNotBeforePriority tests the intersection of NotBefore and Priority: the lower-priority unit that can execute now should.
func (*Suite) TestOneDayInterval ¶
func (s *Suite) TestOneDayInterval()
TestOneDayInterval tests a continuous work spec with a 1-day interval. This is a regression test for a specific parsing issue in the PostgreSQL backend.
func (*Suite) TestPrefilledMeta ¶
func (s *Suite) TestPrefilledMeta()
TestPrefilledMeta tests that WorkSpec.Meta() fills in correctly from "magic" keys in a work spec.
func (*Suite) TestRecreateWorkUnits ¶
func (s *Suite) TestRecreateWorkUnits()
TestRecreateWorkUnits checks that creating work units that already exist works successfully.
func (*Suite) TestRequestSpecificSpec ¶
func (s *Suite) TestRequestSpecificSpec()
TestRequestSpecificSpec verifies that requesting work units for a specific work spec gets the right thing back.
func (*Suite) TestRetryDelay ¶
func (s *Suite) TestRetryDelay()
TestRetryDelay verifies that the delay option on the Retry() call works.
func (*Suite) TestSetDataSetsMeta ¶
func (s *Suite) TestSetDataSetsMeta()
TestSetDataSetsMeta tests that...yeah
func (*Suite) TestSetMeta ¶
func (s *Suite) TestSetMeta()
TestSetMeta tests the basic SetMeta() call and a couple of its documented oddities.
func (*Suite) TestSpecCreateDestroy ¶
func (s *Suite) TestSpecCreateDestroy()
TestSpecCreateDestroy performs basic work spec lifetime tests.
func (*Suite) TestSpecDeletedGone ¶
func (s *Suite) TestSpecDeletedGone()
TestSpecDeletedGone validates that, if you delete a work spec, subsequent attempts to use it return ErrGone.
func (*Suite) TestSpecErrors ¶
func (s *Suite) TestSpecErrors()
TestSpecErrors checks for errors on malformed work specs.
func (*Suite) TestSpecInNamespaceGone ¶
func (s *Suite) TestSpecInNamespaceGone()
TestSpecInNamespaceGone validates that, if you delete a work spec's namespace, attempts to use the work spec return ErrGone.
func (*Suite) TestSummarize ¶
func (s *Suite) TestSummarize()
TestSummarize does a basic (single-work-spec) test of the various Summarize methods.
func (*Suite) TestTrivialWorkUnitFlow ¶
func (s *Suite) TestTrivialWorkUnitFlow()
TestTrivialWorkUnitFlow tests work unit creation, deletion, and existence.
func (*Suite) TestTwoWorkSpecsBasic ¶
func (s *Suite) TestTwoWorkSpecsBasic()
TestTwoWorkSpecsBasic ensures that two work specs can be created and have independent lifetimes.
func (*Suite) TestUnitDeletedGone ¶
func (s *Suite) TestUnitDeletedGone()
TestUnitDeletedGone validates that deleting a work unit causes operations on it to return ErrGone.
func (*Suite) TestUnitSpecDeletedGone ¶
func (s *Suite) TestUnitSpecDeletedGone()
TestUnitSpecDeletedGone validates that deleting a work unit's work spec causes operations on the unit to return ErrGone.
func (*Suite) TestWorkUnitChaining ¶
func (s *Suite) TestWorkUnitChaining()
TestWorkUnitChaining tests that completing work units in one work spec will cause work units to appear in another, if so configured.
func (*Suite) TestWorkUnitData ¶
func (s *Suite) TestWorkUnitData()
TestWorkUnitData validates that the system can store and update data.
func (*Suite) TestWorkUnitOrder ¶
func (s *Suite) TestWorkUnitOrder()
TestWorkUnitOrder is a very basic test that work units get returned in alphabetic order absent any other constraints.
func (*Suite) TestWorkUnitPriorityCtor ¶
func (s *Suite) TestWorkUnitPriorityCtor()
TestWorkUnitPriorityCtor tests that priorities passed in the work unit constructor are honored.
func (*Suite) TestWorkUnitPrioritySet ¶
func (s *Suite) TestWorkUnitPrioritySet()
TestWorkUnitPrioritySet tests two different ways of setting work unit priority.
func (*Suite) TestWorkUnitQueries ¶
func (s *Suite) TestWorkUnitQueries()
TestWorkUnitQueries calls WorkSpec.WorkUnits() with various queries.
func (*Suite) TestWorkerAdoption ¶
func (s *Suite) TestWorkerAdoption()
TestWorkerAdoption hands a child worker to a new parent.
func (*Suite) TestWorkerAncestry ¶
func (s *Suite) TestWorkerAncestry()
TestWorkerAncestry does basic tests on worker parents and children.
func (*Suite) TestWorkerAttempts ¶
func (s *Suite) TestWorkerAttempts()
TestWorkerAttempts checks the association between attempts and workers.
func (*Suite) TestWorkerMetadata ¶
func (s *Suite) TestWorkerMetadata()
TestWorkerMetadata tests the various metadata fields.
func (*Suite) UnitHasPriority ¶
func (s *Suite) UnitHasPriority(unit coordinate.WorkUnit, priority float64) bool
UnitHasPriority validates the priority of a work unit.