goqueue_tests

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package goqueue_tests provides a test suite for general queues

Index

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

  1. Populate async interface using New()
  2. 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
  3. 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 TestDequeueEvent(t *testing.T, rate, timeout time.Duration, newQueue func(size int) interface {
	goqueue.Owner
	goqueue.Enqueuer
	goqueue.Dequeuer
	goqueue.Event
}) func(*testing.T)

func TestDequeueMultiple added in v1.2.0

func TestDequeueMultiple(t *testing.T, rate, timeout time.Duration, newQueue func(size int) interface {
	goqueue.Owner
	goqueue.Enqueuer
	goqueue.Dequeuer
}) func(*testing.T)

func TestEvent added in v1.2.0

func TestEvent(t *testing.T, newQueue func(int) interface {
	goqueue.Owner
	goqueue.Enqueuer
	goqueue.Dequeuer
	goqueue.Event
}) func(*testing.T)

func TestFlush added in v1.2.0

func TestFlush(t *testing.T, rate, timeout time.Duration, newQueue func(int) interface {
	goqueue.Owner
	goqueue.Enqueuer
	goqueue.Dequeuer
}) func(*testing.T)

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 TestLength(t *testing.T, newQueue func(int) interface {
	goqueue.Owner
	goqueue.Enqueuer
	goqueue.Dequeuer
	goqueue.Length
}) func(*testing.T)

func TestPeek added in v1.2.0

func TestPeek(t *testing.T, newQueue func(int) interface {
	goqueue.Owner
	goqueue.Enqueuer
	goqueue.Dequeuer
	goqueue.Peeker
}) func(*testing.T)

func TestPeekFromHead added in v1.2.0

func TestPeekFromHead(t *testing.T, newQueue func(int) interface {
	goqueue.Owner
	goqueue.Enqueuer
	goqueue.Dequeuer
	goqueue.Peeker
}) func(*testing.T)

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

  1. Use the New() function to create/populate a queue of the size for the case
  2. Use the Length() function to verify that the queue is empty (size of 0)
  3. 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.
  4. Use the Length() to check to see if the queue is the expected size
  5. Use the Dequeue() Function again to verify an underflow as the queue should now be empty (length of 0)
  6. Use the Close() function to clean up all internal pointers for the queue

Types

This section is empty.

Jump to

Keyboard shortcuts

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