Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
219eaf6a
Commit
219eaf6a
authored
Mar 14, 2023
by
Andreas Bigger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
table-driven tests for the input threshold function
parent
f208b022
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
25 deletions
+88
-25
channel_config_test.go
op-batcher/batcher/channel_config_test.go
+88
-25
No files found.
op-batcher/batcher/channel_config_test.go
View file @
219eaf6a
...
@@ -7,33 +7,96 @@ import (
...
@@ -7,33 +7,96 @@ import (
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
)
)
// TestInputThreshold tests the [ChannelConfig.InputThreshold] function.
// TestInputThreshold tests the [ChannelConfig.InputThreshold]
// function using a table-driven testing approach.
func
TestInputThreshold
(
t
*
testing
.
T
)
{
func
TestInputThreshold
(
t
*
testing
.
T
)
{
// Construct an empty channel config
type
testInput
struct
{
config
:=
batcher
.
ChannelConfig
{
TargetFrameSize
uint64
SeqWindowSize
:
15
,
TargetNumFrames
int
ChannelTimeout
:
40
,
ApproxComprRatio
float64
MaxChannelDuration
:
1
,
}
SubSafetyMargin
:
4
,
type
test
struct
{
MaxFrameSize
:
120000
,
input
testInput
TargetFrameSize
:
100000
,
want
uint64
TargetNumFrames
:
1
,
ApproxComprRatio
:
0.4
,
}
}
// The input threshold is calculated as: (targetNumFrames * targetFrameSize) / approxComprRatio
// Construct test cases that test the boundary conditions
// Here we see that 100,000 / 0.4 = 100,000 * 2.5 = 250,000
tests
:=
[]
test
{
inputThreshold
:=
config
.
InputThreshold
()
{
require
.
Equal
(
t
,
uint64
(
250
_000
),
inputThreshold
)
input
:
testInput
{
TargetFrameSize
:
1
,
// Set the approximate compression ratio to 0
TargetNumFrames
:
1
,
// Logically, this represents infinite compression,
ApproxComprRatio
:
0.4
,
// so there is no threshold on the size of the input.
},
// In practice, this should never be set to 0.
want
:
2
,
config
.
ApproxComprRatio
=
0
},
{
input
:
testInput
{
TargetFrameSize
:
1
,
TargetNumFrames
:
1
,
ApproxComprRatio
:
1
,
},
want
:
1
,
},
{
input
:
testInput
{
TargetFrameSize
:
1
,
TargetNumFrames
:
1
,
ApproxComprRatio
:
2
,
},
want
:
0
,
},
{
input
:
testInput
{
TargetFrameSize
:
100000
,
TargetNumFrames
:
1
,
ApproxComprRatio
:
0.4
,
},
want
:
250
_000
,
},
{
input
:
testInput
{
TargetFrameSize
:
1
,
TargetNumFrames
:
100000
,
ApproxComprRatio
:
0.4
,
},
want
:
250
_000
,
},
{
input
:
testInput
{
TargetFrameSize
:
100000
,
TargetNumFrames
:
100000
,
ApproxComprRatio
:
0.4
,
},
want
:
25
_000_000_000
,
},
// A compression ratio of 0 means there is no input threshold
{
input
:
testInput
{
TargetFrameSize
:
100000
,
TargetNumFrames
:
100000
,
ApproxComprRatio
:
0
,
},
want
:
uint64
(
0xffffffffffffffff
),
},
{
input
:
testInput
{
TargetFrameSize
:
0
,
TargetNumFrames
:
0
,
ApproxComprRatio
:
0
,
},
want
:
0
,
},
}
// The input threshold will overflow to the max uint64 value
// Validate each test case
receivedThreshold
:=
config
.
InputThreshold
()
for
_
,
tt
:=
range
tests
{
max
:=
config
.
TargetNumFrames
*
int
(
config
.
TargetFrameSize
)
config
:=
batcher
.
ChannelConfig
{
require
.
True
(
t
,
receivedThreshold
>
uint64
(
max
))
TargetFrameSize
:
tt
.
input
.
TargetFrameSize
,
TargetNumFrames
:
tt
.
input
.
TargetNumFrames
,
ApproxComprRatio
:
tt
.
input
.
ApproxComprRatio
,
}
got
:=
config
.
InputThreshold
()
require
.
Equal
(
t
,
tt
.
want
,
got
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment