-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unit tests for node
package + small refactoring & fixes
#5132
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## rc/v1.5.0 #5132 +/- ##
=============================================
+ Coverage 75.74% 76.87% +1.13%
=============================================
Files 650 650
Lines 85464 85470 +6
=============================================
+ Hits 64735 65708 +973
+ Misses 15639 14555 -1084
- Partials 5090 5207 +117
... and 5 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
… into add-unit-tests-for-node-package
} | ||
} | ||
|
||
func (trigger *applicationRunningTrigger) Write(p []byte) (n int, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added, thanks
node/nodeRunner_test.go
Outdated
// src | ||
// +- file2 | ||
// +- dir1 | ||
// +- file3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
node/nodeRunner_test.go
Outdated
err := logger.AddLogObserver(trigger, &logger.PlainFormatter{}) | ||
require.Nil(t, err) | ||
|
||
// start a go routine that will send the SIGINT message after 1 minute |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after 1 second (after the application started)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, indeed, rotten comment.
for k, v := range expectedValues { | ||
assert.Equal(t, v, keys[k], fmt.Sprintf("for key %s", k)) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addition 3: extra tests here
t.Run("should work - metachain", func(t *testing.T) {
t.Parallel()
keys := make(map[string]interface{})
localStatusHandler := &statusHandler.AppStatusHandlerStub{
SetUInt64ValueHandler: func(key string, value uint64) {
keys[key] = value
},
SetStringValueHandler: func(key string, value string) {
keys[key] = value
},
}
localShardCoordinator := &testscommon.ShardsCoordinatorMock{
NoShards: 3,
SelfIDCalled: func() uint32 {
return common.MetachainShardId
},
}
err := InitMetrics(localStatusHandler, pubkeyString, nodeType, localShardCoordinator, nodesSetup, version, economicsConfigs, roundsPerEpoch, minTransactionVersion)
assert.Nil(t, err)
expectedValues := map[string]interface{}{
common.MetricPublicKeyBlockSign: pubkeyString,
common.MetricShardId: uint64(localShardCoordinator.SelfId()),
common.MetricNumShardsWithoutMetachain: uint64(localShardCoordinator.NoShards),
common.MetricNodeType: string(nodeType),
common.MetricRoundTime: uint64(6),
common.MetricAppVersion: version,
common.MetricRoundsPerEpoch: uint64(roundsPerEpoch),
common.MetricCrossCheckBlockHeight: "0",
common.MetricCrossCheckBlockHeight + "_0": uint64(0),
common.MetricCrossCheckBlockHeight + "_1": uint64(0),
common.MetricCrossCheckBlockHeight + "_2": uint64(0),
common.MetricCrossCheckBlockHeightMeta: uint64(0),
common.MetricIsSyncing: uint64(1),
common.MetricLeaderPercentage: fmt.Sprintf("%f", 2.0),
common.MetricDenomination: uint64(4),
common.MetricShardConsensusGroupSize: uint64(63),
common.MetricMetaConsensusGroupSize: uint64(400),
common.MetricNumNodesPerShard: uint64(402),
common.MetricNumMetachainNodes: uint64(401),
common.MetricStartTime: uint64(111111),
common.MetricRoundDuration: uint64(6000),
common.MetricMinTransactionVersion: uint64(1),
common.MetricNumValidators: uint64(0),
common.MetricConsensusGroupSize: uint64(400),
}
assert.Equal(t, len(expectedValues), len(keys))
for k, v := range expectedValues {
assert.Equal(t, v, keys[k], fmt.Sprintf("for key %s", k))
}
})
t.Run("should work - invalid shard id", func(t *testing.T) {
t.Parallel()
keys := make(map[string]interface{})
localStatusHandler := &statusHandler.AppStatusHandlerStub{
SetUInt64ValueHandler: func(key string, value uint64) {
keys[key] = value
},
SetStringValueHandler: func(key string, value string) {
keys[key] = value
},
}
localShardCoordinator := &testscommon.ShardsCoordinatorMock{
NoShards: 3,
SelfIDCalled: func() uint32 {
return 10
},
}
err := InitMetrics(localStatusHandler, pubkeyString, nodeType, localShardCoordinator, nodesSetup, version, economicsConfigs, roundsPerEpoch, minTransactionVersion)
assert.Nil(t, err)
assert.Equal(t, uint64(0), keys[common.MetricConsensusGroupSize])
})
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added, thanks
{ | ||
LeaderPercentage: 2, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addition 2: extra entry here:
{ | |
LeaderPercentage: 2, | |
}, | |
{ | |
LeaderPercentage: 2, | |
}, | |
{ | |
LeaderPercentage: 2, | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
@@ -329,3 +332,185 @@ func TestInitRatingsMetrics(t *testing.T) { | |||
assert.Equal(t, v, keys[k]) | |||
} | |||
} | |||
|
|||
func TestInitMetrics(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% coverage can be reached on this component using the next 3 additions:
addition 1:
- on L140, as part of
TestInitConfigMetrics
, addMaxNodesChangeEnableEpoch
MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{
{
EpochEnable: 0,
MaxNumNodes: 1,
NodesToShufflePerShard: 2,
},
},
then on L190 we'll need new expected metrics:
"erd_max_nodes_change_enable_epoch0_epoch_enable": uint32(0),
"erd_max_nodes_change_enable_epoch0_max_num_nodes": uint32(1),
"erd_max_nodes_change_enable_epoch0_nodes_to_shuffle_per_shard": uint32(2),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added, thanks.
node/nodeRunner_test.go
Outdated
) | ||
|
||
// these exceptions appear because the delayedComponent prevented the call of the first 2 components | ||
// as the closable components are called in revered order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// as the closable components are called in revered order | |
// as the closable components are called in reversed order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
node/nodeRunner_test.go
Outdated
) | ||
|
||
// these exceptions appear because the delayedComponent prevented the call of the first 2 components | ||
// as the closable components are called in revered order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// as the closable components are called in revered order | |
// as the closable components are called in reversed order |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
assert.Equal(tb, numKeys, len(closedCalled)) | ||
} | ||
|
||
func contains(needle string, haystack []string) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System test passed.
@@ Log scanner @@
add-unit-tests-for-node-package
================================================================================
- Known Warnings 14
- New Warnings 2
- Known Errors 0
- New Errors 1
- Panics 0
================================================================================ - block hash does not match 10938
- wrong nonce in block 3558
- miniblocks does not match 0
- num miniblocks does not match 0
- miniblock hash does not match 0
- block bodies does not match 0
- receipts hash missmatch 0
================================================================================ - No jailed nodes on the thestnet
================================================================================
56bf141
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored some tests due to this comment: #5141 (comment)
@@ -216,3 +216,18 @@ func TestFeeComputer_InHighConcurrency(t *testing.T) { | |||
|
|||
wg.Wait() | |||
} | |||
|
|||
func TestFullHistoryPruningStorer_IsInterfaceNil(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func TestFullHistoryPruningStorer_IsInterfaceNil(t *testing.T) { | |
func TestFeeComputer_IsInterfaceNil(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
too much copy-paste :D
Thanks.
t.Parallel() | ||
|
||
var lf *logsFacade | ||
require.True(t, check.IfNil(lf)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.True(t, check.IfNil(lf)) | |
require.True(t, lf.IsInterfaceNil()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done on the whole package
Kept check.IfNil
call whenever the function under test returned an interface (compatible with NilInterfaceChecker).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok!
PubKeyConverter: testscommon.NewPubkeyConverterMock(32), | ||
} | ||
lf, _ = NewLogsFacade(arguments) | ||
require.False(t, check.IfNil(lf)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require.False(t, check.IfNil(lf)) | |
require.False(t, lf.IsInterfaceNil()) |
node
package + small refactoring & fixes
Reasoning behind the pull request
Proposed changes
Testing procedure
stats
directory should now contain thegenesisSmartContracts.json
and thegasSchedules
directory and all the gas schedules files.Pre-requisites
Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:
feat
branch created?feat
branch merging, do all satellite projects have a proper tag insidego.mod
?