Skip to content

Commit

Permalink
updated workflows and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-alexander committed Sep 24, 2023
1 parent cc16cc0 commit 7b5ede7
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 92 deletions.
81 changes: 52 additions & 29 deletions .github/workflows/go-queue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,68 @@ name: go-queue

on:
push:
branches: ["main"]
pull_request:
release:
types: [published]
branches:
- main
paths:
- "./"
- ".github/workflows/go-queue.yml"

env:
LINTER_VERSION: "v1.51.2"
GO_VERSION: "1.19"

jobs:
version:
environment:
runs-on: ubuntu-latest
env:
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
steps:
- name: Get git source
run: |
git_source=`echo $GITHUB_REF | sed 's/refs\/heads\///'`
git_source=`echo $git_source | sed 's/refs\/tags\///'`
git_source=`echo $git_source | sed 's/refs\\///'`
echo $git_source
echo "git_source=$git_source" >> $GITHUB_ENV
- name: Get git SHA
run: |
git_sha=`echo $GITHUB_SHA`
echo $git_sha
echo "git_sha=$git_sha" >> $GITHUB_ENV
- name: Checkout repository code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Get version
run: |
version=`cat /home/runner/work/go-queue/go-queue/version.json | jq '.Version' | sed 's/"//g'`
echo $version
echo "version=$version" >> $GITHUB_ENV
version_source=`cat /home/runner/work/go-queue/go-queue/version.json | jq '.Version' | sed 's/"//g'`
echo $version_source
echo "version_source=$version_source" >> $GITHUB_ENV
- name: Generate build artifacts
run: |
mkdir -p /tmp
echo ${{ env.version }} >> /tmp/version
echo ${{ env.version_source }} >> /tmp/version_source
echo ${{ env.git_source }} >> /tmp/git_source
echo ${{ env.git_sha }} >> /tmp/git_sha
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
/tmp/version
/tmp/version_source
/tmp/git_source
/tmp/git_sha
go_lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.16
- uses: actions/checkout@v3
go-version: ${{ env.GO_VERSION }}
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.44.2
version: ${{ env.LINTER_VERSION }}
working-directory: .
args: --verbose

Expand All @@ -50,9 +74,9 @@ jobs:
contents: read
steps:
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.16
- name: Test go-queue/finite
Expand All @@ -68,7 +92,7 @@ jobs:
go mod download
go test -v ./... -coverprofile /tmp/go-queue-infinite.out > /tmp/go-queue-infinite.log
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
Expand All @@ -79,28 +103,27 @@ jobs:
retention-days: 1

git_push_tag:
if: github.ref == 'refs/heads/main'
needs: [go_test, version]
needs: [go_test, environment]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: artifacts
path: /tmp
- name: Get version
run: |
version=`cat /tmp/version`
version=`cat /tmp/version_source`
echo "version=$version" >> $GITHUB_ENV
- name: Check out repository code
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: "0"
- name: Push/Update go-queue version
uses: anothrNick/github-tag-action@1.36.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
CUSTOM_TAG: v${{ env.version }}
# - name: Push/Update go-queue version
# uses: anothrNick/github-tag-action@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# WITH_V: true
# CUSTOM_TAG: v${{ env.version }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions example.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"reflect"
)

//REFERENCE: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
// REFERENCE: https://stackoverflow.com/questions/22892120/how-to-generate-a-random-string-of-a-fixed-length-in-go
func randomString(nLetters ...int) string {
letterRunes := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
nLetter := 20
Expand All @@ -21,8 +21,8 @@ func randomString(nLetters ...int) string {
}

type Example struct {
Int int `json:"int,omitempty"`
Float float64 `json:"float,omitempty"`
Int int `json:"int,omitempty,string"`
Float float64 `json:"float,omitempty,string"`
String string `json:"string,omitempty"`
}

Expand Down Expand Up @@ -118,7 +118,7 @@ func ExampleFlush(queue Dequeuer) []*Example {
return ExampleConvertMultiple(queue.Flush())
}

//ExampleGenFloat64 will generate a random number of random float values if n is equal to 0
// ExampleGenFloat64 will generate a random number of random float values if n is equal to 0
// not to exceed the constant TestMaxExamples, if n is provided, it will generate that many items
func ExampleGenFloat64(sizes ...int) []*Example {
size := int(rand.Float64() * 100)
Expand Down
55 changes: 30 additions & 25 deletions infinite/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,22 @@ import (

const casef string = "case: %s"

//TestEnqueue attempt to unit test the enqueue function, in general it confirms the
// TestEnqueue attempt to unit test the enqueue function, in general it confirms the
// behavior, that for an infinite queue, no matter how much data you put into the
// queue, the queue will never overflow and there will be no data loss. This test
// also assumes that the "size" of the queue won't affect the behavior of enqueue
// 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 can handle valid data, as a plus the example data type supports the
// BinaryMarshaller
//
// Some assumptions this test won't make:
// - order is maintained
// - the "size" of the queue affects the behavior of enqueue
// - order is maintained
// - the "size" of the queue affects the behavior of enqueue
func TestEnqueue(t *testing.T, rate, timeout time.Duration, newQueue func() interface {
goqueue.Owner
goqueue.Enqueuer
Expand Down Expand Up @@ -86,19 +88,21 @@ func TestEnqueue(t *testing.T, rate, timeout time.Duration, newQueue func() inte
}
}

//TestEnqueueMultiple will attempt to unit test the EnqueueMultiple function;
// TestEnqueueMultiple will attempt to unit test the EnqueueMultiple function;
// for an infinite queue, this function will never overflow nor will it return
// items that weren't able to be enqueued.
// 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 can handle valid data, as a plus the example data type supports the
// BinaryMarshaller
//
// Some assumptions this test won't make:
// - order is maintained
// - the "size" of the queue affects the behavior of enqueue
// - order is maintained
// - the "size" of the queue affects the behavior of enqueue
func TestEnqueueMultiple(t *testing.T, rate, timeout time.Duration, newQueue func() interface {
goqueue.Owner
goqueue.Enqueuer
Expand Down Expand Up @@ -162,20 +166,22 @@ func TestEnqueueMultiple(t *testing.T, rate, timeout time.Duration, newQueue fun
}
}

//TestEnqueueInFront will validate that if there is data in the queue and you attempt to
// TestEnqueueInFront will validate that if there is data in the queue and you attempt to
// enqueue in front, that special "data" will go to the front, while if the queue is empty
// that data will just be "in" the queue (a regular queue if the queue is empty).
// 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 TestEnqueueInFront(t *testing.T, rate, timeout time.Duration, newQueue func() interface {
goqueue.Owner
goqueue.Enqueuer
Expand Down Expand Up @@ -224,8 +230,7 @@ func TestEnqueueInFront(t *testing.T, rate, timeout time.Duration, newQueue func
item, underflow := goqueue.MustDequeue(q, ctx.Done(), rate)
cancel()
assert.False(t, underflow)
assert.IsType(t, &goqueue.Example{}, item, casef, cDesc)
example, _ := item.(*goqueue.Example)
example := goqueue.ExampleConvertSingle(item)
assert.Equal(t, c.iInFrontValue, example, casef, cDesc)

//flush the queue to empty it
Expand All @@ -238,7 +243,7 @@ func TestEnqueueInFront(t *testing.T, rate, timeout time.Duration, newQueue func
}
}

//TestEnqueueEvent will confirm that the signal channels function correctly when data is enqueued,
// TestEnqueueEvent will confirm that the signal channels function correctly when data is enqueued,
// this function for an infinite queue is slightly different because it can't be lossless, there's
// no way to properly implement a buffered channel with an infinite queue
// Some assumptions this test does make:
Expand Down
Loading

0 comments on commit 7b5ede7

Please sign in to comment.