forked from ava-labs/avalanchego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/dev' into discon_restart
- Loading branch information
Showing
14 changed files
with
554 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package network | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
const ( | ||
localhost = "127.0.0.1:9651" | ||
) | ||
|
||
func TestNoConnMeter(t *testing.T) { | ||
m := NewConnMeter(0, 1) | ||
|
||
count, err := m.Register(localhost) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, count) | ||
|
||
count, err = m.Register(localhost) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, count) | ||
} | ||
|
||
func TestConnMeter(t *testing.T) { | ||
m := NewConnMeter(time.Hour, 1) | ||
|
||
count, err := m.Register(localhost) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, count) | ||
|
||
count, err = m.Register(localhost) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, count) | ||
} | ||
|
||
func TestConnMeterReplace(t *testing.T) { | ||
remote := "127.0.0.2:9651" | ||
differentPort := "127.0.0.1:9650" | ||
m := NewConnMeter(time.Hour, 1) | ||
|
||
count, err := m.Register(localhost) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, count) | ||
|
||
count, err = m.Register(differentPort) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 1, count) | ||
|
||
count, err = m.Register(remote) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, count) | ||
|
||
count, err = m.Register(localhost) | ||
assert.NoError(t, err) | ||
assert.Equal(t, 0, count) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package formatting | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"testing" | ||
) | ||
|
||
func BenchmarkEncodings(b *testing.B) { | ||
benchmarks := []struct { | ||
encoding string | ||
size int | ||
}{ | ||
{ | ||
encoding: CB58Encoding, | ||
size: 1 << 10, // 1kb | ||
}, | ||
{ | ||
encoding: CB58Encoding, | ||
size: 1 << 11, // 2kb | ||
}, | ||
{ | ||
encoding: CB58Encoding, | ||
size: 1 << 12, // 4kb | ||
}, | ||
{ | ||
encoding: CB58Encoding, | ||
size: 1 << 13, // 8kb | ||
}, | ||
{ | ||
encoding: CB58Encoding, | ||
size: 1 << 14, // 16kb | ||
}, | ||
{ | ||
encoding: CB58Encoding, | ||
size: 1 << 15, // 32kb | ||
}, | ||
{ | ||
encoding: HexEncoding, | ||
size: 1 << 10, // 1kb | ||
}, | ||
{ | ||
encoding: HexEncoding, | ||
size: 1 << 12, // 4kb | ||
}, | ||
{ | ||
encoding: HexEncoding, | ||
size: 1 << 15, // 32kb | ||
}, | ||
{ | ||
encoding: HexEncoding, | ||
size: 1 << 17, // 128kb | ||
}, | ||
{ | ||
encoding: HexEncoding, | ||
size: 1 << 18, // 256kb | ||
}, | ||
{ | ||
encoding: HexEncoding, | ||
size: 1 << 19, // 512kb | ||
}, | ||
{ | ||
encoding: HexEncoding, | ||
size: 1 << 20, // 1mb | ||
}, | ||
{ | ||
encoding: HexEncoding, | ||
size: 1 << 21, // 2mb | ||
}, | ||
{ | ||
encoding: HexEncoding, | ||
size: 1 << 22, // 4mb | ||
}, | ||
} | ||
manager, _ := NewEncodingManager(HexEncoding) | ||
for _, benchmark := range benchmarks { | ||
enc, _ := manager.GetEncoding(benchmark.encoding) | ||
bytes := make([]byte, benchmark.size) | ||
_, _ = rand.Read(bytes) // #nosec G404 | ||
b.Run(fmt.Sprintf("%s-%d bytes", benchmark.encoding, benchmark.size), func(b *testing.B) { | ||
for n := 0; n < b.N; n++ { | ||
_ = enc.ConvertBytes(bytes) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.