Skip to content
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

refactor: Move a transport protocol-related logic from the framework core #280

Merged
merged 4 commits into from
May 19, 2021
Merged

refactor: Move a transport protocol-related logic from the framework core #280

merged 4 commits into from
May 19, 2021

Conversation

jakubkoci
Copy link
Contributor

I did some refactorings to help me add support for multiple transports in the following PR:

  • Add test to MessageSender
  • Move up a logic from EnvelopeService to MessageSender
  • Remove transport-related details from the TransportService and from the core of the framework.
  • Rename transport to session which hopefully express the meaning better.

As a next step I'm considering:

  • Rename transporters to transports
  • Move up more logic from MessageSender.packMessage and pass service object to packMessage
  • Then we could call packMessage and sendMessage for every available service. Eventually, we could remove the logic from createOutboundMessage.
  • Improve validation of outboundMessage inside OutboundTransporter and error handling
  • Add multiple transports

If you think it doesn't make sense to merge this without full functionality I can continue with adding changes. But I realized that it contains a good amount of changes already and it could be worth merging sooner.

@jakubkoci jakubkoci requested a review from a team as a code owner May 19, 2021 08:49
@jakubkoci jakubkoci changed the title Refactor/websockets refactor: Move a transport protocol-related logic from the framework core May 19, 2021
src/agent/MessageSender.ts Outdated Show resolved Hide resolved
src/agent/MessageSender.ts Outdated Show resolved Hide resolved
src/agent/__tests__/MessageSender.test.ts Outdated Show resolved Hide resolved
jest.mock('../TransportService')
jest.mock('../EnvelopeService')

const logger = testLogger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just import logger from ../../__tests__/logger?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like const logger = testLogger more because you can simply change it to const logger = new ConsoleLogger(...) when want to log into the console during the development.

src/agent/__tests__/MessageSender.test.ts Outdated Show resolved Hide resolved
* @returns mock function with type annotations
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function mockFunction<T extends (...args: any[]) => any>(fn: T): jest.MockedFunction<T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we import this from the helpers file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I didn't know about that. I updated the JS doc at least :)

Comment on lines +10 to +18
export class WebSocketTransportSession implements TransportSession {
public readonly type = 'websocket'
public socket?: WebSocket

public constructor(socket?: WebSocket) {
this.socket = socket
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the transport session for the inbound transport, outbound transport or both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. That's a good question. I would say it's for both. A developer sets the session when calling agent.recieveMessage(message, session) passing inbound message. Then it can be used for outbound messages.

@TimoGlastra
Copy link
Contributor

TimoGlastra commented May 19, 2021

My last PR broke the test and got into main 😬. I'm on it

Fixed in #282

Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
…text

Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
@jakubkoci
Copy link
Contributor Author

Thanks, @TimoGlastra for the review and suggestions 👍 PR updated.

@codecov-commenter
Copy link

Codecov Report

Merging #280 (4334ba0) into main (e5efce0) will decrease coverage by 0.12%.
The diff coverage is 85.41%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #280      +/-   ##
==========================================
- Coverage   88.76%   88.63%   -0.13%     
==========================================
  Files         216      216              
  Lines        3899     3881      -18     
  Branches      438      431       -7     
==========================================
- Hits         3461     3440      -21     
- Misses        438      441       +3     
Impacted Files Coverage Δ
src/agent/helpers.ts 92.30% <ø> (ø)
src/types.ts 100.00% <ø> (ø)
src/transport/WsOutboundTransporter.ts 82.35% <69.23%> (-3.65%) ⬇️
src/agent/MessageReceiver.ts 86.44% <75.00%> (ø)
src/agent/TransportService.ts 92.59% <80.00%> (-7.41%) ⬇️
src/agent/Agent.ts 98.59% <100.00%> (ø)
src/agent/EnvelopeService.ts 100.00% <100.00%> (ø)
src/agent/MessageSender.ts 100.00% <100.00%> (+4.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e5efce0...4334ba0. Read the comment docs.

@jakubkoci jakubkoci merged commit dc3a575 into openwallet-foundation:main May 19, 2021
@jakubkoci jakubkoci deleted the refactor/websockets branch June 24, 2021 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants