-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fail Stream Replicator on startup if source or target isn't reachable #183
Conversation
cc541a4
to
e5e7c65
Compare
e5e7c65
to
adb452b
Compare
There are tests commented out for most of the sources and targets, which were written as a means of documenting the requirement. Even where we don't have any code changes, we should uncomment those tests to ensure that for every source and target behaves as we expect. If the pre-existing tests themselves require changes that's fine - but let's document why. Ofc it's always fine to add more tests too. |
@colmsnowplow I have went through all sources and targets and uncommented and fixed those tests. |
@@ -395,19 +395,3 @@ func TestNewEventHubTarget_ConnVarsErr(t *testing.T) { | |||
assert.EqualError(err, `Error initialising EventHub client: could not reach Event Hub: dial tcp: lookup test.servicebus.windows.net: no such host`) | |||
assert.Nil(tgt) | |||
} | |||
|
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 test was removed as the same behaviour is tested in the unit test above it.
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.
It doesn't look like the same behaviour to me...
There are two ways to authenticate against EH - connection string or key value. In the scenario where no valid combination of the required env vars for one of the two methods is present, the client doesn't provide a good debugging experience - so we manually check this in the code. The existing unit tests are for that check.
If the correct env vars are provided, however, we can still fail to connect to the client - it might be unavailable, the credentials provided might be incorrect, etc. So another test should be needed to check 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.
I’m having a hard time understanding the issue here, it seems to me that the test that I deleted was not even correct after all. It sets env vars for EVENTHUB_KEY_NAME
and EVENTHUB_KEY_VALUE
and expects a No valid combination of authentication Env vars found
error, which would not be the case. That error would appear if no env vars have been set, either for the connection string or the eventhub key. This possibility is tested above in TestNewEventHubTarget_CredentialsNotFound
.
I might be missing something here so please if you could provide a bit more context on this, or even book a quick chat about it it would be really helpful.
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.
Taking a second look, you're right, the different possible failures are indeed accounted for. I think I just looked in the wrong place and confused myself - these tests are indeed fine.
v1 has been merged, |
@@ -77,7 +76,6 @@ func TestNewPubSubSource_Failure(t *testing.T) { | |||
assert.Nil(pubsubSource) | |||
// This should return an error when we can't connect, rather than proceeding to the Write() function before we hit a problem. |
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.
nit - would be nice to check for the error message as you have done for other sources
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.
@@ -61,10 +61,12 @@ func TestNewSQSSourceWithInterfaces_Failure(t *testing.T) { | |||
|
|||
source, err := newSQSSourceWithInterfaces(client, "00000000000", 10, testutil.AWSLocalstackRegion, "nonexistent-queue") | |||
|
|||
assert.Nil(source) | |||
assert.NotNil(err) | |||
assert.NotNil(source) |
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's the rationale for doing 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.
As newSqsSourceWithInterfaces
just returns a new sqsSource
regardless of the parameters it gets and never errors, the assertion we had there was wrong.
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.
Right but the issue this PR is for is to establish behaviour where functions like this one fail when we can't connect. The test is meant to illustrate that desired behaviour - so the test should stay as it was and the behaviour of the function should change in this PR
assert.Nil(err) | ||
|
||
err = source.Read(nil) | ||
assert.True(strings.HasPrefix(err.Error(), `Failed to get SQS queue URL`)) |
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 err is nil this will panic - see the rest of the tests in the project on (on master at least) for pattern that avoids 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.
Fixed.
assert.Equal("Hello Server!!", string(result)) | ||
} | ||
|
||
assert.Equal(int64(10), ackOps) | ||
} | ||
|
||
func TestHttpWrite_Failure(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.
This test was intended for a separate case to connection error - providing a bad path was just an easy way to achieve it.
It's to test the behaviour of stream replicator when requests fail.
Rather than removing a test for this case, we should amend the test to fail some other way.
For example, a malformed request body would achieve it. Or, we could add a case to the http server to respond to a given path with a success for the HEAD request, but a failure for all other requests.
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.
Great idea with the path, I've added an exception in the http client to look for the /error
path and return a 500 error if the request does not have the HEAD
method. This allows us to test that the HEAD
connection test can be successful but other requests can fail and test the behaviour.
assert.NotNil(err) | ||
pubsubTarget, err := newPubSubTarget(`project-test`, `test-topic-wrong`) | ||
|
||
assert.EqualError(err, `Connection to PubSub failed, topic does not exist`) |
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.
Damn, wish I knew about EqualError
before I spent ages wrapping stuff across the project in if statements 🤦
Added connection checks to:
Tested the rest of the sources and targets and they are checked on start-up.