Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
backend:
name: GoCryptoTrader backend (${{ matrix.os }}, ${{ matrix.goarch }}, psql=${{ matrix.psql }}, skip_wrapper_tests=${{ matrix.skip_wrapper_tests}}, sonic=${{ matrix.sonic }})
name: GoCryptoTrader (${{ matrix.os }}, ${{ matrix.goarch }}, psql=${{ matrix.psql }}, skip_wrapper_tests=${{ matrix.skip_wrapper_tests}}, sonic=${{ matrix.sonic }})
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -118,9 +118,51 @@ jobs:
uses: codecov/codecov-action@v5
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

backend-live-test-build:
name: GoCryptoTrader mock_test_off build (ubuntu-latest, amd64, psql=true, sonic=false)
runs-on: ubuntu-latest
env:
GCT_SKIP_LIVE_TESTS: true

steps:
- name: Cancel previous workflow runs
uses: styfle/cancel-workflow-action@0.13.0
with:
access_token: ${{ github.token }}

- name: Setup Postgres
uses: ikalnytskyi/action-setup-postgres@v8
with:
database: gct_dev_ci
id: postgres

- name: Set up Postgres environment
run: |
echo "PSQL_USER=postgres" >> $GITHUB_ENV
echo "PSQL_PASS=postgres" >> $GITHUB_ENV
echo "PSQL_HOST=localhost" >> $GITHUB_ENV
echo "PSQL_DBNAME=gct_dev_ci" >> $GITHUB_ENV
echo "PSQL_TESTDBNAME=gct_dev_ci" >> $GITHUB_ENV
echo "PSQL_SSLMODE=disable" >> $GITHUB_ENV
echo "PSQL_SKIPSQLCMD=true" >> $GITHUB_ENV
shell: bash

- name: Checkout code
uses: actions/checkout@v6

- name: Setup Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}

- name: Build tests with mock_test_off
run: |
go test -run=^$ -tags=mock_test_off ./...
shell: bash

backend-docker:
name: GoCryptoTrader backend docker (ubuntu-latest, amd64, psql=false, skip_wrapper_tests=true, sonic=false)
name: GoCryptoTrader docker (ubuntu-latest, amd64, psql=false, skip_wrapper_tests=true, sonic=false)
runs-on: ubuntu-latest

steps:
Expand Down
9 changes: 8 additions & 1 deletion exchanges/binance/binance_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ import (
"os"
"testing"

"github.com/thrasher-corp/gocryptotrader/exchange/stream"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
"github.com/thrasher-corp/gocryptotrader/internal/testing/livetest"
)

var mockTests = false

func TestMain(m *testing.M) {
if livetest.ShouldSkip() {
log.Printf(livetest.LiveTestingSkipped, "Binance")
os.Exit(0)
}

e = new(Exchange)
if err := testexch.Setup(e); err != nil {
log.Fatalf("Binance Setup error: %s", err)
Expand All @@ -40,7 +47,7 @@ func TestMain(m *testing.M) {
}
}
}
e.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
e.Websocket.DataHandler = stream.NewRelay(sharedtestvalues.WebsocketRelayBufferCapacity)
log.Printf(sharedtestvalues.LiveTesting, e.Name)
if err := e.UpdateTradablePairs(context.Background()); err != nil {
log.Fatalf("Binance UpdateTradablePairs error: %s", err)
Expand Down
6 changes: 6 additions & 0 deletions exchanges/bybit/bybit_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,17 @@ import (
"github.com/thrasher-corp/gocryptotrader/currency"
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
"github.com/thrasher-corp/gocryptotrader/internal/testing/livetest"
)

var mockTests = false

func TestMain(m *testing.M) {
if livetest.ShouldSkip() {
log.Printf(livetest.LiveTestingSkipped, "Bybit")
os.Exit(0)
}

e = testInstance()

if e.API.AuthenticatedSupport {
Expand Down
3 changes: 2 additions & 1 deletion exchanges/poloniex/poloniex_live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"testing"

"github.com/thrasher-corp/gocryptotrader/exchange/stream"
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
)
Expand All @@ -25,7 +26,7 @@ func TestMain(m *testing.M) {
e.SetCredentials(apiKey, apiSecret, "", "", "", "")
}
log.Printf(sharedtestvalues.LiveTesting, e.Name)
e.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
e.Websocket.DataHandler = stream.NewRelay(sharedtestvalues.WebsocketRelayBufferCapacity)
e.Websocket.TrafficAlert = sharedtestvalues.GetWebsocketStructChannelOverride()
os.Exit(m.Run())
}
46 changes: 46 additions & 0 deletions exchanges/request/context_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package request

import "context"

const contextVerboseFlag verbosity = "verbose"

type verbosity string

// WithVerbose adds verbosity to a request context so that specific requests
// can have distinct verbosity without impacting all requests.
func WithVerbose(ctx context.Context) context.Context {
return context.WithValue(ctx, contextVerboseFlag, true)
}

// IsVerbose checks main verbosity first then checks context verbose values
// for specific request verbosity.
func IsVerbose(ctx context.Context, verbose bool) bool {
if !verbose {
verbose, _ = ctx.Value(contextVerboseFlag).(bool)
}
return verbose
}

type delayNotAllowedKey struct{}

// WithDelayNotAllowed adds a value to the context that indicates that no delay is allowed for rate limiting.
func WithDelayNotAllowed(ctx context.Context) context.Context {
return context.WithValue(ctx, delayNotAllowedKey{}, struct{}{})
}

func hasDelayNotAllowed(ctx context.Context) bool {
_, ok := ctx.Value(delayNotAllowedKey{}).(struct{})
return ok
}

type retryNotAllowedKey struct{}

// WithRetryNotAllowed adds a value to the context that indicates that no retries are allowed for requests.
func WithRetryNotAllowed(ctx context.Context) context.Context {
return context.WithValue(ctx, retryNotAllowedKey{}, struct{}{})
}

func hasRetryNotAllowed(ctx context.Context) bool {
_, ok := ctx.Value(retryNotAllowedKey{}).(struct{})
return ok
}
33 changes: 33 additions & 0 deletions exchanges/request/context_helpers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package request

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestIsVerbose(t *testing.T) {
t.Parallel()
require.False(t, IsVerbose(t.Context(), false))
require.True(t, IsVerbose(t.Context(), true))
require.True(t, IsVerbose(WithVerbose(t.Context()), false))
require.False(t, IsVerbose(context.WithValue(t.Context(), contextVerboseFlag, false), false))
require.False(t, IsVerbose(context.WithValue(t.Context(), contextVerboseFlag, "bruh"), false))
require.True(t, IsVerbose(context.WithValue(t.Context(), contextVerboseFlag, true), false))
}

func TestWithDelayNotAllowed(t *testing.T) {
t.Parallel()
assert.True(t, hasDelayNotAllowed(WithDelayNotAllowed(t.Context())))
assert.False(t, hasDelayNotAllowed(t.Context()))
assert.False(t, hasDelayNotAllowed(WithRetryNotAllowed(WithVerbose(t.Context()))))
}

func TestWithRetryNotAllowed(t *testing.T) {
t.Parallel()
assert.True(t, hasRetryNotAllowed(WithRetryNotAllowed(t.Context())))
assert.False(t, hasRetryNotAllowed(t.Context()))
assert.False(t, hasRetryNotAllowed(WithDelayNotAllowed(WithVerbose(t.Context()))))
}
12 changes: 0 additions & 12 deletions exchanges/request/limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,3 @@ func (r *Requester) EnableRateLimiter() error {
}
return nil
}

type delayNotAllowedKey struct{}

// WithDelayNotAllowed adds a value to the context that indicates that no delay is allowed for rate limiting.
func WithDelayNotAllowed(ctx context.Context) context.Context {
return context.WithValue(ctx, delayNotAllowedKey{}, struct{}{})
}

func hasDelayNotAllowed(ctx context.Context) bool {
_, ok := ctx.Value(delayNotAllowedKey{}).(struct{})
return ok
}
8 changes: 0 additions & 8 deletions exchanges/request/limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,6 @@ func TestNewBasicRateLimit(t *testing.T) {
assert.Same(t, defs[Auth], defs[UnAuth], "Auth and UnAuth should be same instance")
}

func TestWithDelayNotAllowed(t *testing.T) {
t.Parallel()

assert.True(t, hasDelayNotAllowed(WithDelayNotAllowed(t.Context())))
assert.False(t, hasDelayNotAllowed(t.Context()))
assert.False(t, hasDelayNotAllowed(WithVerbose(t.Context())))
}

func TestCancelAll(t *testing.T) {
t.Parallel()

Expand Down
Loading
Loading