-
Notifications
You must be signed in to change notification settings - Fork 110
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
RSDK-8663: Optimize away gostream concurrency complexity for camera clients. #4363
Changes from all commits
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 |
---|---|---|
|
@@ -506,3 +506,17 @@ func TestServer(t *testing.T) { | |
test.That(t, err.Error(), test.ShouldContainSubstring, errStreamFailed.Error()) | ||
}) | ||
} | ||
|
||
//nolint | ||
func TestCameraClientIsReadImager(t *testing.T) { | ||
// RSDK-8663: Enforce that a camera client always satisfies the optimized `ReadImager` | ||
// interface. | ||
cameraClient, err := camera.NewClientFromConn(nil, nil, "", resource.Name{}, nil) | ||
test.That(t, err, test.ShouldBeNil) | ||
|
||
if _, isReadImager := cameraClient.(camera.ReadImager); isReadImager { | ||
// Success | ||
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. Curious syntax Wondering why you prefer this? 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. How this code got this way is a bit of a long story -- it wasn't due to preference. I was trying to use the "test.ShouldImplement" assertion, that I think requires reflection and additional error handling. But ultimately failed at that. So the structure of this if-statement was already there and I just had to use a type-assertion instead and do nothing in the "then" clause. That said, I do think writing conditionals in the affirmative (i.e: avoid double negatives) reads better. And in this case, a real writer is going to write the if-statement that way -- just with a non-empty "then". But normally I wouldn't take that to the "extreme" of having an empty "then" clause. I just left it this way because I was fed up with writing an assertion. 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. Haha the test lib use of reflection can be super funky Got it |
||
} else { | ||
t.Fatalf("Camera client is expected to be a `ReadImager`. Client type: %T", cameraClient) | ||
} | ||
} |
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 see since the client
Read
func is guaranteed to only call GetImage once in its bodyThere 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! That's exactly how this patch works. Instead of spinning up:
We first ask "Hey camera, do you have a "Read" method?" Great -- we'll just call that one time and avoid this stream non-sense.