requester: defer execution of request.Item generation in closure (#723)

* requester: defer execution of request.Item generation in closure.

* bithumb: fix issue

* coinut/itbit: fix linter issues

* binance: fix bug on recvWindow setting

* requester: standardize sendpayload + add readme update

* nonce: remove inc() function

* request: defer unlockiflocked

* binance: revert changes for open orders

* btcmarkets: defer auth generation functionality, rm context deadline as this will be created just before sending HTTP request.

* binance: move const to top

* exmo: remove debug output as its generated in the requester function

* ftx: defer auth functionality

* requester: move error to top

* bittrex: defer auth functionality

* bitmex: defer auth functionality and remove deadline as generation occurs after rate limiting.

* btse: defer auth functionality

* coinbasepro: defer auth functionality and removed context deadline as this is generated after rate limiting

* coinbene: defer auth functionality and remove context deadline as this is generated after rate limiting

* huobi: defer auth functionality and remove context deadline as this is generated after rate limiting

* huobi-futures: defer auth functionality and remove context deadline as this is generated after rate limiting

* kraken: defer auth functionality and remove context deadline as this is generated after rate limiting

* kraken: remove deadline protection for timestamp generation

* okgroup: defer auth functionality and remove context deadline as this is generated after rate limiting

* poloniex: defer auth functionality

* zb: defer auth functionality and remove context deadline as this is generated after rate limiting

* exchanges: clean up log output which are done and inspected in the requester package

* binance: fix path bug on every retry, rm timeout context as this is not needed

* coinbene: fix path bug on retry

* binance: consolidate functionality

* coinbene: fix linter issues

* poloniex: linter fix

* kraken: change add -> set

* bitstamp: fix path bug for retry

* BTSE: fix retry path bug

* coinbene: fix path bug whoopsie by me

* gateio: fix bug where on retry it does not reset reader

* localbitcoins: fix path bug on retry

* zb: change domain to land

* exchanges: make sure io.Reader is generated every request

* exchanges: move reader generation into function scope

* wrapper_issues: setup exchange manager

* engine: expand withdraw manager test

* engine: dont look for environment

* bitstamp: fix pathing bug (@thrasher-)

* engine/withdraw_manager: purge tests as this is covered in repository withdraw
This commit is contained in:
Ryan O'Hara-Reid
2021-08-06 17:24:38 +10:00
committed by GitHub
parent 2da239735f
commit 279b53827f
46 changed files with 1471 additions and 1324 deletions

View File

@@ -11,13 +11,6 @@ type Nonce struct {
m sync.Mutex
}
// Inc increments the nonce value
func (n *Nonce) Inc() {
n.m.Lock()
n.n++
n.m.Unlock()
}
// Get retrives the nonce value
func (n *Nonce) Get() Value {
n.m.Lock()
@@ -27,8 +20,10 @@ func (n *Nonce) Get() Value {
// GetInc increments and returns the value of the nonce
func (n *Nonce) GetInc() Value {
n.Inc()
return n.Get()
n.m.Lock()
defer n.m.Unlock()
n.n++
return Value(n.n)
}
// Set sets the nonce value

View File

@@ -1,21 +1,10 @@
package nonce
import (
"sync"
"testing"
"time"
)
func TestInc(t *testing.T) {
var nonce Nonce
nonce.Set(1)
nonce.Inc()
expected := Value(2)
result := nonce.Get()
if result != expected {
t.Errorf("Expected %d got %d", expected, result)
}
}
func TestGet(t *testing.T) {
var nonce Nonce
nonce.Set(112321313)
@@ -65,12 +54,13 @@ func TestNonceConcurrency(t *testing.T) {
var nonce Nonce
nonce.Set(12312)
var wg sync.WaitGroup
wg.Add(1000)
for i := 0; i < 1000; i++ {
go nonce.Inc()
go func() { nonce.GetInc(); wg.Done() }()
}
// Allow sufficient time for all routines to finish
time.Sleep(time.Second)
wg.Wait()
result := nonce.Get()
expected := Value(12312 + 1000)