Documentation ¶
Overview ¶
Package goqueue_tests provides a test suite for general queues
Index ¶
- func TestAsync(t *testing.T, newQueue func(int) interface{ ... }) func(*testing.T)
- func TestDequeue(t *testing.T, rate, timeout time.Duration, ...) func(*testing.T)
- func TestDequeueEvent(t *testing.T, rate, timeout time.Duration, ...) func(*testing.T)
- func TestDequeueMultiple(t *testing.T, rate, timeout time.Duration, ...) func(*testing.T)
- func TestEvent(t *testing.T, newQueue func(int) interface{ ... }) func(*testing.T)
- func TestFlush(t *testing.T, rate, timeout time.Duration, newQueue func(int) interface{ ... }) func(*testing.T)
- func TestGarbageCollect(t *testing.T, rate, timeout time.Duration, ...) func(*testing.T)
- func TestLength(t *testing.T, newQueue func(int) interface{ ... }) func(*testing.T)
- func TestPeek(t *testing.T, newQueue func(int) interface{ ... }) func(*testing.T)
- func TestPeekFromHead(t *testing.T, newQueue func(int) interface{ ... }) func(*testing.T)
- func TestQueue(t *testing.T, rate, timeout time.Duration, newQueue func(int) interface{ ... }) func(*testing.T)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestAsync ¶ added in v1.2.0
func TestAsync(t *testing.T, newQueue func(int) interface { goqueue.Owner goqueue.Enqueuer goqueue.Dequeuer }) func(*testing.T)
TestAsync
- Populate async interface using New()
- Create two goRoutines: a. goRoutine (dequeue): (2) Stop when signal received after enqueue function is finished enqueing data (1) Constantly attempt to dequeue, when underflow is false, add item to slice of float64 b. goRoutine (enqueue): (1) Enqueue all the data from randFloats, store data in queue (2) Send signal when finished enqueuing data
- Compare the items dequeued to the items enqueued, they should be equal although their quantity may not be the same (see verification)
func TestDequeue ¶ added in v1.2.0
func TestDequeue(t *testing.T, rate, timeout time.Duration, newQueue func(size int) interface { goqueue.Owner goqueue.Enqueuer goqueue.Dequeuer }) func(*testing.T)
TestDequeue will confirm the functionality of the underflow output, with an infinite queue the expectation is that the enqueue will never overflow, and the dequeue will only underflow if the queue is empty. Although this use case is the "same" for infinite and finite queues the dequeue function is based on the behavior of the enqueue function. This test has some "configuration" items that can be "tweaked" for your specific queue implementation:
- rate: this is the rate at which the test will attempt to enqueue/dequeue
- timeout: this is when the test will "give up"
Some assumptions this test does make:
- your queue can handle valid data, as a plus the example data type supports the BinaryMarshaller
- your queue maintains order
- it's safe to use a single instance of your queue for each test case
Some assumptions this test won't make:
- the "size" of the queue affects the behavior of enqueue
func TestDequeueEvent ¶ added in v1.2.2
func TestDequeueMultiple ¶ added in v1.2.0
func TestGarbageCollect ¶ added in v1.2.0
func TestGarbageCollect(t *testing.T, rate, timeout time.Duration, newQueue func(size int) interface { goqueue.Enqueuer goqueue.Dequeuer goqueue.Owner goqueue.GarbageCollecter }) func(*testing.T)
TestGarbageCollect attempts to validate that memory is returned to the heap and can be properly garbage collected it executes and garbage collection is manually triggered. This makes some heavy underlying assumptions that a slice or map data structure. The idea behind the function is that it'll re-create those data structures with new maps/slices such that that the items can be de-allocated. This test attempts to put a significant amount of data on the heap to validate it's functionality
func TestLength ¶ added in v1.2.0
func TestPeekFromHead ¶ added in v1.2.0
func TestQueue ¶ added in v1.2.0
func TestQueue(t *testing.T, rate, timeout time.Duration, newQueue func(int) interface { goqueue.Owner goqueue.Enqueuer goqueue.Dequeuer }) func(*testing.T)
TestQueue
- Use the New() function to create/populate a queue of the size for the case
- Use the Length() function to verify that the queue is empty (size of 0)
- Use the Enqueue() function for the number of itemsIn to place data in the queue and verify that the length increases by one each time.
- Use the Length() to check to see if the queue is the expected size
- Use the Dequeue() Function again to verify an underflow as the queue should now be empty (length of 0)
- Use the Close() function to clean up all internal pointers for the queue
Types ¶
This section is empty.