-
Notifications
You must be signed in to change notification settings - Fork 829
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
Corrected port number validation range #304
Changes from 8 commits
368910c
da29522
f1f1fb1
2eeea60
18d6715
fef3127
ce70699
ecfd86c
1c09831
3a9fa73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
import java.util.List; | ||
import java.util.Properties; | ||
import java.util.concurrent.CountDownLatch; | ||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.io.IOUtils; | ||
import org.pytorch.serve.http.DescribeModelResponse; | ||
import org.pytorch.serve.http.ErrorResponse; | ||
|
@@ -94,7 +95,8 @@ public void afterSuite() { | |
@Test | ||
public void test() | ||
throws InterruptedException, HttpPostRequestEncoder.ErrorDataEncoderException, | ||
IOException, NoSuchFieldException, IllegalAccessException { | ||
IOException, NoSuchFieldException, IllegalAccessException, | ||
GeneralSecurityException, InvalidSnapshotException { | ||
Channel channel = null; | ||
Channel managementChannel = null; | ||
for (int i = 0; i < 5; ++i) { | ||
|
@@ -189,6 +191,8 @@ public void test() | |
testUnregisterModelFailure("noopversioned", "1.2.1"); | ||
|
||
testTS(); | ||
testTSValidPort(); | ||
testTSInvalidPort(); | ||
} | ||
|
||
public void testTS() | ||
|
@@ -1244,4 +1248,65 @@ private void testMetricManager() throws JsonParseException, InterruptedException | |
} | ||
} | ||
} | ||
|
||
private void testTSValidPort() | ||
throws InterruptedException, GeneralSecurityException, InvalidSnapshotException, | ||
IOException { | ||
// test case for verifying port range refer https://github.com/pytorch/serve/issues/291 | ||
server.stop(); | ||
System.setProperty("tsConfigFile", "src/test/resources/config_port.properties"); | ||
FileUtils.deleteQuietly(new File(System.getProperty("LOG_LOCATION"), "config")); | ||
ConfigManager.init(new ConfigManager.Arguments()); | ||
configManager = ConfigManager.getInstance(); | ||
PluginsManager.getInstance().initialize(); | ||
|
||
InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE); | ||
server = new ModelServer(configManager); | ||
server.start(); | ||
|
||
Channel channel = null; | ||
Channel managementChannel = null; | ||
for (int i = 0; i < 5; ++i) { | ||
channel = TestUtils.connect(false, configManager); | ||
if (channel != null) { | ||
break; | ||
} | ||
Thread.sleep(100); | ||
} | ||
|
||
for (int i = 0; i < 5; ++i) { | ||
managementChannel = TestUtils.connect(true, configManager); | ||
if (managementChannel != null) { | ||
break; | ||
} | ||
Thread.sleep(100); | ||
} | ||
|
||
Assert.assertNotNull(channel, "Failed to connect to inference port."); | ||
Assert.assertNotNull(managementChannel, "Failed to connect to management port."); | ||
|
||
testPing(channel); | ||
} | ||
|
||
private void testTSInvalidPort() | ||
throws InterruptedException, GeneralSecurityException, InvalidSnapshotException, | ||
IOException { | ||
// test case for verifying port range refer https://github.com/pytorch/serve/issues/291 | ||
// invalid port test | ||
server.stop(); | ||
System.setProperty("tsConfigFile", "src/test/resources/config_invalid_port.properties"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking about this test a little more. Since this test is only testing hte JAVA code path, couldn't we simply modify the TS_INFERENCE_ADDRESS property in ConfigManager and restart the server? Do we need this additional config.properties file? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 This is a much simpler approach. Thanks. |
||
FileUtils.deleteQuietly(new File(System.getProperty("LOG_LOCATION"), "config")); | ||
ConfigManager.init(new ConfigManager.Arguments()); | ||
configManager = ConfigManager.getInstance(); | ||
PluginsManager.getInstance().initialize(); | ||
|
||
InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE); | ||
server = new ModelServer(configManager); | ||
try { | ||
server.start(); | ||
} catch (Exception e) { | ||
Assert.assertEquals(e.getClass(), IllegalArgumentException.class); | ||
Assert.assertEquals(e.getMessage(), "Invalid port number: https://127.0.0.1:65536"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
inference_address=https://127.0.0.1:65536 | ||
management_address=unix:/tmp/management.sock | ||
# model_server_home=../.. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove the commented properties in test configurations. |
||
model_store=../modelarchive/src/test/resources/models | ||
enable_envvars_config=true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
inference_address=https://127.0.0.1:42523 | ||
management_address=unix:/tmp/management.sock | ||
model_store=../modelarchive/src/test/resources/models | ||
enable_envvars_config=true |
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.
I am curious to know what this file is, that we are deleting.
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.
Due to snapshot feature, the first preference will be given to last available snapshot file instead of the properties file set in the system properties. Thus cleaning up the generated snapshot before restart.
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.
Why is snapshot given a preference over the runtime configuration? Whats the order of preference for this?
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 preference order for properties file is as follows :