-
Notifications
You must be signed in to change notification settings - Fork 130
[PAN-2577] Integration Integration test(s) on p2p of 'net_services' #1402
[PAN-2577] Integration Integration test(s) on p2p of 'net_services' #1402
Conversation
9f7e06d
to
f8e6392
Compare
To answer the question in the PR description, that is exactly what we are trying to fix. There was a unit tests that mocked things up differently that passed at a unit level. What we need is a non-mocked test where pantheon is stood up and we see all the ports we opened in We need a test that fails against revision |
e41902e
to
64efbdc
Compare
assertThat(expectation.get("jsonrpc").get("port")).isEqualTo(result.get("jsonrpc").get("port")); | ||
assertThat(expectation.get("ws").get("host")).isEqualTo(result.get("ws").get("host")); | ||
assertThat(expectation.get("ws").get("port")).isEqualTo(result.get("ws").get("port")); | ||
assertThat(expectation.get("p2p").get("host")).isEqualTo(result.get("p2p").get("host")); |
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.
You're not checking the p2p port value here
expectation.put("jsonrpc", constituentMap); | ||
expectation.put("ws", constituentMap); | ||
expectation.put("p2p", constituentMap); | ||
assertThat(expectation.get("jsonrpc").get("host")).isEqualTo(result.get("jsonrpc").get("host")); |
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.
The format of assertThat
should be: assertThat(actual).isEqualTo(expected)
- these checks should be reformatted.
} | ||
|
||
@Test | ||
public void adminAddPeerForcesConnection() { |
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.
This method should be renamed
new HashMap() { | ||
{ | ||
put("host", "127.0.0.1"); | ||
put("port", "0"); |
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.
Expecting a port of "0" for everything is a little confusing. Can you explicitly configure the json-rpc and ws ports to distinct values?
noDiscoveryCluster.start(nodeA, nodeB); | ||
} | ||
|
||
@Test |
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.
Can you add a test case where all net services (json-rpc, ws, and p2p) are disabled?
72e6872
to
d3372f0
Compare
0727e0b
to
fed6f6e
Compare
} | ||
return (netServicesResponse != null ? netServicesResponse.getResult() : null) != null | ||
? netServicesResponse.getResult() | ||
: null; |
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.
Looks like you've got an extra ternary operator here 😄
...pantheon/tests/acceptance/dsl/condition/net/ExpectNetServicesReturnsAllServicesAsActive.java
Show resolved
Hide resolved
@@ -68,6 +71,10 @@ public AdminJsonRpcRequestFactory admin() { | |||
return admin; | |||
} | |||
|
|||
public NetServicesJsonRpcRequestFactory netServices() { |
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.
What do you think about renaming NetServicesJsonRpcRequestFactory
to something like CustomNetJsonRpcRequestFactory
. Then if we end up expanding the "net_" api in the future, we can add more methods to this factory. Then this method would become customNet()
.
public Request<?, NetServicesResponse> netServices() { | ||
|
||
return new Request<>( | ||
"net_services", Collections.EMPTY_LIST, web3jService, NetServicesResponse.class); |
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.
"net_services", Collections.EMPTY_LIST, web3jService, NetServicesResponse.class); | |
"net_services", Collections.emptyList(), web3jService, NetServicesResponse.class); |
If you use emptyList()
here, you can remove the annotation @SuppressWarnings({"unchecked", "rawtypes"})
Request<?, NetServicesJsonRpcRequestFactory.NetServicesResponse> request = | ||
netServicesJsonRpcRequestFactory.netServices(); | ||
netServicesResponse = request.send(); | ||
} catch (final Exception ignored) { |
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.
You shouldn't ignore an exception here, you should throw.
netServicesResponse = request.send(); | ||
} catch (final Exception ignored) { | ||
} | ||
return netServicesResponse != null ? netServicesResponse.getResult() : null; |
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.
You shouldn't need to check for null. Just move the return statement into the try block and throw the exception instead of ignoring it and you can return getResult()
directly.
final ClusterConfiguration clusterConfiguration = | ||
new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build(); | ||
noDiscoveryCluster = new Cluster(clusterConfiguration, net); | ||
nodeA = pantheon.createArchiveNodeWithDiscoveryDisabledAndAdmin("nodeA"); |
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.
Can you add a utility for creating a node with all net services turned on?
.../src/test/java/tech/pegasys/pantheon/tests/acceptance/jsonrpc/NetServicesAcceptanceTest.java
Show resolved
Hide resolved
nodeB = pantheon.createArchiveNodeNetServicesDisabled("nodeB"); | ||
noDiscoveryCluster.start(nodeA, nodeB); | ||
|
||
nodeA.verify(net.netServicesNotActive()); |
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.
You could create a generic method that can be configured with expected services: net.netServices(List<String> expectedServices)
2aa359d
to
e71f7ab
Compare
CustomNetJsonRpcRequestFactory.NetServicesResponse netServicesResponse = request.send(); | ||
netServicesActive = netServicesResponse.getResult(); | ||
} catch (final Exception e) { | ||
LOG.error("Error parsing response to 'net_services' json-rpc request.", e); |
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.
This should throw, not log an error
LOG.error("Error parsing response to 'net_services' json-rpc request.", e); | |
throw new RuntimeException(e); |
} catch (final Exception e) { | ||
LOG.error("Error parsing response to 'net_services' json-rpc request.", e); | ||
} | ||
return netServicesActive; |
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.
If the catch rethrows, you don't need this extra return statement
assertThat(NetworkUtility.isValidPort(p2pPort) || jsonRpcPort == 0).isTrue(); | ||
} | ||
|
||
public static class ExpectNetServicesReturnsNoServicesAsActiveX implements Condition { |
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.
public static class ExpectNetServicesReturnsNoServicesAsActiveX implements Condition { | |
public static class ExpectNetServicesReturnsOnlyJsonRpcActive implements Condition { |
assertThat(NetworkUtility.isValidPort(p2pPort) || jsonRpcPort == 0).isTrue(); | ||
} | ||
|
||
public static class ExpectNetServicesReturnsNoServicesAsActiveX implements Condition { |
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.
Can you make this an independent class in a separate file rather than an internal class?
@@ -68,6 +71,10 @@ public AdminJsonRpcRequestFactory admin() { | |||
return admin; | |||
} | |||
|
|||
public CustomNetJsonRpcRequestFactory netServices() { |
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.
Can you make the naming for CustomNetJsonRpcRequestFactory
-related variables and methods consistent? So this would be: customNet()
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.
This method name still needs to be updated
this.web3jService = web3jService; | ||
} | ||
|
||
public Request<?, NetServicesResponse> customNet() { |
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.
public Request<?, NetServicesResponse> customNet() { | |
public Request<?, NetServicesResponse> netServices() { |
@@ -34,13 +35,15 @@ public JsonRequestFactories( | |||
final PermissioningJsonRpcRequestFactory perm, | |||
final AdminJsonRpcRequestFactory admin, | |||
final EeaJsonRpcRequestFactory eea, | |||
final CustomNetJsonRpcRequestFactory netServices, |
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.
final CustomNetJsonRpcRequestFactory netServices, | |
final CustomNetJsonRpcRequestFactory customNet, |
@@ -25,6 +25,7 @@ | |||
private final PermissioningJsonRpcRequestFactory perm; | |||
private final AdminJsonRpcRequestFactory admin; | |||
private final EeaJsonRpcRequestFactory eea; | |||
private final CustomNetJsonRpcRequestFactory netServices; |
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.
private final CustomNetJsonRpcRequestFactory netServices; | |
private final CustomNetJsonRpcRequestFactory customNet; |
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.
You missed one method name update, but otherwise looks good! Please update before merging.
@@ -68,6 +71,10 @@ public AdminJsonRpcRequestFactory admin() { | |||
return admin; | |||
} | |||
|
|||
public CustomNetJsonRpcRequestFactory netServices() { |
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.
This method name still needs to be updated
6de788a
to
bfd2078
Compare
PR description
An acceptance tests for
PAN-2577
.Fixed Issue(s)
Ensures the proper performance of the
net_services
endpoint.