test: remove port dependency from integration tests (#574).#650
test: remove port dependency from integration tests (#574).#650mattklein123 merged 6 commits intoenvoyproxy:masterfrom
Conversation
| } | ||
|
|
||
| Network::ListenSocket* InstanceImpl::getListenSocketByIndex(uint32_t index) { | ||
| if (index < config_->listeners().size()) { |
There was a problem hiding this comment.
nit: this is kind of an odd impl for this function (requiring advancing from beginning by N each time). I know this is only used in test code, but can we potentially implement with a for loop over list elements which also increments an index?
There was a problem hiding this comment.
Why's it faster to iterate over the list rather than advance an iterator? AFAIK, you can't randomly access an element in std::list, so you have to do something O(n).
There was a problem hiding this comment.
Sorry, nevermind, I misread. This is fine.
| // Network::FilterChainFactory | ||
| bool createFilterChain(Network::Connection& connection) override; | ||
|
|
||
| uint32_t port() const { return socket_->localAddress()->ip()->port(); } |
There was a problem hiding this comment.
nit: can we move this above 161 (makes it clear which functions are part of interface overrides). I'm not totally crazy that we have a port() function here either since FakeUpstream also does UDS. Can we just return localAddress maybe and then have the caller deal with the right thing to do depending on case?
| if (it != port_map().end()) { | ||
| return it->second; | ||
| } | ||
| return 0; |
There was a problem hiding this comment.
should we crash/fail/print here?
| } | ||
|
|
||
| ServerContextPtr SslIntegrationTest::createUpstreamSslContext() { | ||
| static Stats::TestIsolatedStoreImpl upstream_stats_store; |
There was a problem hiding this comment.
Why was this change made? I think this is fragile since I think we have tests that look at stats which might then not reset.
There was a problem hiding this comment.
The problem is that if you share a stats store between the Envoy server instance and upstream instance, you get into a dependency cycle. Previously the call to createUpstreamSslContext happened after the test_server_ was initialized. Now we need the test server to be created after the upstream, to allow the upstream to find its bound port and substitute the port into the JSON config prior to initializing the test server.
The test code doesn't check the stats for the upstream instances, only for the test server AFAICT.
There was a problem hiding this comment.
OK sounds good, as long as nothing is being checked right now should be fine.
| * Obtain socket the admin endpoint is bound to. | ||
| * @return Network::ListenSocket& socket reference. | ||
| */ | ||
| virtual Network::ListenSocket& socket() PURE; |
There was a problem hiding this comment.
Can we return a const Network::ListenSocket& here since callers just need to get local address?
| server_(options_, hooks_, restart_, stats_store_, fakelock_, component_factory_, | ||
| local_info_) {} | ||
| ServerInstanceImplTest() { | ||
| options_.reset(new testing::NiceMock<MockOptions>(TestEnvironment::temporaryFileSubstitutePorts( |
There was a problem hiding this comment.
Why did this need to get changed to pointers here? It seems like we could have just passed result of temporaryFileSubstitutePorts to constructor?
There was a problem hiding this comment.
Yeah, no need to change to pointers, I had at first thought the port map construction would be more involved, but it's not.
|
|
||
| # TODO(htuch): Clean this up when Bazelifying the hot restart test below. | ||
| HOT_RESTART_JSON="$TEST_SRCDIR"/test/config/integration/hot_restart.json | ||
| cat "$TEST_TMPDIR"/test/config/integration/server.json | |
There was a problem hiding this comment.
This used to test socket passing, but I don't think it actually does anymore since each listener now binds to a random port? Is there any way to restore the old behavior that is sane? At least can we put in TODO to restore the old test behavior?
There was a problem hiding this comment.
TODO added. One idea is we could add a flag to allow us to write back to the filesystem (or print to stdout) the JSON corresponding to what's actually used when zero port binding - basically the same JSON object we parsed but with addresses replaced based on the discovered ports. This would generalize to be useful in other cross-process integration tests where we can't access the ListenSocket objects directly. Another alternative is to do log scraping and JSON templating outside of Envoy. What do you think?
There was a problem hiding this comment.
Yeah I kind of like the idea of just spitting the JSON back out, or just generally having some way to have an admin endpoint that maybe spits out the listener list in JSON with the real ports. I think this is complex enough to fix and the risk of regression is low enough that I'm fine deferring this for now. We should open a GH issue though that specifically tracks various tech debt cleanups (or just track specifically in the making build better issue) from the migration just to make sure that we don't lose them in "TODO noise".
There was a problem hiding this comment.
Added #654. I like the idea of making this an admin endpoint feature, but if we bind the admin http address to 0 as well as we'd like to in tests, we need to find the admin endpoint. Maybe we could just have a flag that provides this address and return the rest from the admin endpoint?
There was a problem hiding this comment.
I don't see how the flag would work unless it somehow talked to the existing process over RPC.
Actually, think the shared memory stuff might also be broken for bazel? How does that work? It definitely won't allow concurrently running the main server.
Let's just discuss in #654.
| Http::CodecClient::Type type); | ||
| IntegrationTcpClientPtr makeTcpConnection(uint32_t port); | ||
|
|
||
| // Test-wide port map. |
There was a problem hiding this comment.
When you say that bazel runs tests in parallel, I assume you mean in parallel in different processes, right? Otherwise it seems like this static port map is not going to work.
There was a problem hiding this comment.
That's correct. Each individual _test.cc becomes an independent test target that is run in a separate process, and these may run in parallel. Within a _test.cc, gtest will run all tests sequentially in the same process.
Add subset of struct Node protobuf for use by Wasm.
Signed-off-by: Jose Nino <jnino@lyft.com> Signed-off-by: JP Simard <jp@jpsim.com>
Signed-off-by: Jose Nino <jnino@lyft.com> Signed-off-by: JP Simard <jp@jpsim.com>
No description provided.