From 6e5d5abd5b35b1dae4fbd4166253d34cc7dc9390 Mon Sep 17 00:00:00 2001 From: Antonio Alexander Date: Sun, 19 Mar 2023 16:59:33 -0500 Subject: [PATCH] Updated the test to properly use the example type --- CHANGELOG.md | 4 ++++ tests/tests.go | 59 ++++++++++++++++++++++++++------------------------ version.json | 2 +- 3 files changed, 36 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c32dba..5284fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this service will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.2.3] - 03/19/22 + +- Fixed the TestQueue test such that it used the example properly and would work even if the items returned was a slice of bytes + ## [1.2.2] - 09/10/22 - Added "Must" functions that will block until success diff --git a/tests/tests.go b/tests/tests.go index 2394473..4cb59d1 100644 --- a/tests/tests.go +++ b/tests/tests.go @@ -37,7 +37,7 @@ func randomString(nLetters ...int) string { return string(b) } -//TestGarbageCollect attempts to validate that memory is returned to the heap and can be properly +// 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 @@ -92,20 +92,22 @@ func TestGarbageCollect(t *testing.T, rate, timeout time.Duration, newQueue func } } -//TestDequeue will confirm the functionality of the underflow output, with an infinite queue +// 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" +// - 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 +// - 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 +// - the "size" of the queue affects the behavior of enqueue func TestDequeue(t *testing.T, rate, timeout time.Duration, newQueue func(size int) interface { goqueue.Owner goqueue.Enqueuer @@ -593,14 +595,14 @@ func TestLength(t *testing.T, newQueue func(int) interface { } } -//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 +// 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 func TestQueue(t *testing.T, rate, timeout time.Duration, newQueue func(int) interface { goqueue.Owner goqueue.Enqueuer @@ -635,9 +637,10 @@ func TestQueue(t *testing.T, rate, timeout time.Duration, newQueue func(int) int for i := 0; i < len(c.iFloats); i++ { ctx, cancel := context.WithTimeout(context.TODO(), timeout) defer cancel() - value, underflow := goqueue.MustDequeue(q, ctx.Done(), rate) + item, underflow := goqueue.MustDequeue(q, ctx.Done(), rate) cancel() if assert.False(t, underflow, casef, cDesc) { + value := goqueue.ExampleConvertSingle(item) assert.Equal(t, c.iFloats[i], value, casef, cDesc) } } @@ -648,16 +651,16 @@ func TestQueue(t *testing.T, rate, timeout time.Duration, newQueue func(int) int } } -//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) +// 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 TestAsync(t *testing.T, newQueue func(int) interface { goqueue.Owner goqueue.Enqueuer diff --git a/version.json b/version.json index 4a6bc58..fae382e 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "Version": "1.2.2" + "Version": "1.2.3" }