Project

General

Profile

Actions

Feature #4024

closed

NetworkMonitor: stub implementation

Added by Junxiao Shi over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Utils
Target version:
Start date:
Due date:
% Done:

100%

Estimated time:
5.00 h

Description

In NetworkMonitor, allow getNetworkInterface and listNetworkInterfaces return value to be mocked in a test case.


Related issues 3 (0 open3 closed)

Related to ndn-cxx - Feature #4025: NetworkMonitor: empty impl on unsupported platformClosedJunxiao Shi

Actions
Blocks NFD - Feature #4021: FaceSystem: use NetworkMonitor::listNetworkInterfaces()ClosedJunxiao Shi

Actions
Blocked by ndn-cxx - Feature #3353: NetworkMonitor: emit fine-grained signals when the state of a network interface changesClosedDavide Pesavento

Actions
Actions #1

Updated by Junxiao Shi over 7 years ago

  • Blocks Feature #4021: FaceSystem: use NetworkMonitor::listNetworkInterfaces() added
Actions #2

Updated by Junxiao Shi over 7 years ago

  • Blocked by Feature #3353: NetworkMonitor: emit fine-grained signals when the state of a network interface changes added
Actions #3

Updated by Junxiao Shi over 7 years ago

  • Related to Feature #4025: NetworkMonitor: empty impl on unsupported platform added
Actions #4

Updated by Junxiao Shi over 7 years ago

  • Status changed from New to In Progress
  • Assignee set to Junxiao Shi

Design:

  • Pure virtual base class NetworkMonitor::ImplBase is introduced. It is a friend of NetworkMonitor, and offers protected methods to modify NetworkMonitor data structures or emit signals on it. ImplBase type is public API.
  • Existing Impl class inherit from ImplBase. It is not a friend of NetworkMonitor, but accesses NetworkMonitor data structures and signals via ImplBase protected methods. Impl type is not public API.
  • NetworkMonitor constructor takes unique_ptr<NetworkMonitor::ImplBase>, which defaults to nullptr. Passing nullptr causes the constructor to internally make an Impl instance.
  • NetworkInterface type setters are made public. NetworkMonitor APIs that return NetworkInterface are changed to return const NetworkInterface instead so that setters cannot be invoked by outsider.
  • MockImpl class inherits from ImplBase and exposes its protected methods as public. To make a mock NetworkMonitor, pass a MockImpl instance to NetworkMonitor constructor.
Actions #5

Updated by Davide Pesavento over 7 years ago

Junxiao Shi wrote:

  • NetworkInterface type setters are made public.

I'd rather keep them private.

Actions #6

Updated by Junxiao Shi over 7 years ago

Reply to note-5:

How would you propose to let a test case create and update a NetworkInterface?
What's the harm of making the setters public? If someone uses const_cast, it's their problem. Testability is more important than absolute protection.

Actions #7

Updated by Davide Pesavento over 7 years ago

@Junxiao, are you still working on this?

Actions #8

Updated by Junxiao Shi over 7 years ago

I'm waiting for the design discussion to be resolved.

For coding, I'm waiting for #3817 to close in order to avoid conflicts.

Actions #9

Updated by Davide Pesavento over 7 years ago

  • Blocked by Feature #3817: NetworkMonitor fine-grained signals for macOS added
Actions #10

Updated by Davide Pesavento over 7 years ago

  • Blocked by deleted (Feature #3817: NetworkMonitor fine-grained signals for macOS)
Actions #11

Updated by Davide Pesavento over 7 years ago

The main change of #3817 has been merged. Remaining changes under that task will be minor and localized, thus this task is no longer blocked by #3817.

Actions #12

Updated by Junxiao Shi over 7 years ago

  • % Done changed from 0 to 20
  • Estimated time set to 5.00 h

https://gerrit.named-data.net/3978 patchset1 illustrates some of the API changes. I've skipped macOS variant for now. It also does not include MockImpl yet.

Actions #13

Updated by Junxiao Shi over 7 years ago

  • % Done changed from 20 to 40

https://gerrit.named-data.net/3978 patchset2 brings the public API design of MockNetworkMonitor. It's structured as a subclass of NetworkMonitor rather than an Impl, because the Impl is passed by unique_ptr to NetworkMonitor and thus is solely owned by NetworkMonitor, so it's unsafe for the caller to keep a reference to an Impl. Instead, MockNetworkMonitor can internally manage an Impl and forward calls to it.

Actions #14

Updated by Junxiao Shi over 7 years ago

  • Status changed from In Progress to Code review
  • % Done changed from 40 to 100
Actions #15

Updated by Alex Afanasyev over 7 years ago

  • Status changed from Code review to Closed
Actions #16

Updated by Davide Pesavento over 7 years ago

  • Subject changed from NetworkMonitor: mock impl to NetworkMonitor: stub implementation
Actions

Also available in: Atom PDF