Skip to content

Commit

Permalink
Merge pull request #409 from atsign-foundation/gkc/at-client-update
Browse files Browse the repository at this point in the history
build: take up latest at_client
  • Loading branch information
gkc authored Sep 15, 2023
2 parents c15cdcd + ac4c62f commit 3cbaf2a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class SecondaryUrlFinder {
final int _rootPort;
late final AtLookupSecureSocketFactory _socketFactory;

SecondaryUrlFinder(this._rootDomain, this._rootPort, {AtLookupSecureSocketFactory? socketFactory}) {
SecondaryUrlFinder(this._rootDomain, this._rootPort,
{AtLookupSecureSocketFactory? socketFactory}) {
_socketFactory = socketFactory ?? AtLookupSecureSocketFactory();
}

Expand Down
21 changes: 14 additions & 7 deletions packages/at_lookup/test/connection_management_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ void main() {
when(() =>
mockSocketFactory.createSocket('test.test.test', '12345', any()))
.thenAnswer((invocation) {
return Future<SecureSocket>.value(createMockAtServerSocket('test.test.test', 12345));
return Future<SecureSocket>.value(
createMockAtServerSocket('test.test.test', 12345));
});
});

Expand Down Expand Up @@ -95,7 +96,8 @@ void main() {
test(
'test message listener closes connection'
' when socket listener onDone is called', () async {
OutboundConnection oc = OutboundConnectionImpl(createMockAtServerSocket('test.test.test', 12345));
OutboundConnection oc = OutboundConnectionImpl(
createMockAtServerSocket('test.test.test', 12345));
OutboundMessageListener oml = OutboundMessageListener(oc);
expect((oc.getSocket() as MockSecureSocket).destroyed, false);
expect(oc.metaData?.isClosed, false);
Expand All @@ -107,7 +109,8 @@ void main() {
test(
'test message listener closes connection'
' when socket listener onError is called', () async {
OutboundConnection oc = OutboundConnectionImpl(createMockAtServerSocket('test.test.test', 12345));
OutboundConnection oc = OutboundConnectionImpl(
createMockAtServerSocket('test.test.test', 12345));
OutboundMessageListener oml = OutboundMessageListener(oc);
expect((oc.getSocket() as MockSecureSocket).destroyed, false);
expect(oc.metaData?.isClosed, false);
Expand All @@ -117,7 +120,8 @@ void main() {
});

test('test can safely call connection.close() repeatedly', () async {
OutboundConnection oc = OutboundConnectionImpl(createMockAtServerSocket('test.test.test', 12345));
OutboundConnection oc = OutboundConnectionImpl(
createMockAtServerSocket('test.test.test', 12345));
OutboundMessageListener oml = OutboundMessageListener(oc);
expect((oc.getSocket() as MockSecureSocket).destroyed, false);
expect(oc.metaData?.isClosed, false);
Expand All @@ -136,7 +140,8 @@ void main() {
test(
'test that OutboundMessageListener.closeConnection will call'
' connection.close if the connection is idle', () async {
OutboundConnection oc = OutboundConnectionImpl(createMockAtServerSocket('test.test.test', 12345));
OutboundConnection oc = OutboundConnectionImpl(
createMockAtServerSocket('test.test.test', 12345));
OutboundMessageListener oml = OutboundMessageListener(oc);
expect((oc.getSocket() as MockSecureSocket).destroyed, false);
expect(oc.metaData?.isClosed, false);
Expand All @@ -156,7 +161,8 @@ void main() {
test(
'test that OutboundMessageListener.closeConnection will not call'
' connection.close if already marked closed', () async {
OutboundConnection oc = OutboundConnectionImpl(createMockAtServerSocket('test.test.test', 12345));
OutboundConnection oc = OutboundConnectionImpl(
createMockAtServerSocket('test.test.test', 12345));
OutboundMessageListener oml = OutboundMessageListener(oc);
expect((oc.getSocket() as MockSecureSocket).destroyed, false);
oc.metaData!.isClosed = true;
Expand All @@ -170,7 +176,8 @@ void main() {
test(
'test that OutboundMessageListener.closeConnection will call'
' connection.close even if the connection is marked stale', () async {
OutboundConnection oc = OutboundConnectionImpl(createMockAtServerSocket('test.test.test', 12345));
OutboundConnection oc = OutboundConnectionImpl(
createMockAtServerSocket('test.test.test', 12345));
OutboundMessageListener oml = OutboundMessageListener(oc);
expect((oc.getSocket() as MockSecureSocket).destroyed, false);
expect(oc.metaData?.isClosed, false);
Expand Down
44 changes: 26 additions & 18 deletions packages/at_lookup/test/secondary_address_cache_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ void main() async {
});

test('test lookup of @alice on non-existent atDirectory', () async {
CacheableSecondaryAddressFinder cache = CacheableSecondaryAddressFinder('root.no.no.no', 64);
CacheableSecondaryAddressFinder cache =
CacheableSecondaryAddressFinder('root.no.no.no', 64);
expect(() async => await cache.findSecondary('@alice'),
throwsA(predicate((e) => e is RootServerConnectivityException)));
});
Expand Down Expand Up @@ -128,7 +129,9 @@ void main() async {
// });
});

group('some cache tests with a real SecondaryUrlFinder on a mocked root server', () {
group(
'some cache tests with a real SecondaryUrlFinder on a mocked root server',
() {
registerFallbackValue(SecureSocketConfig());
String atSign = '@alice';
String noAtAtSign = atSign.replaceFirst('@', '');
Expand Down Expand Up @@ -163,14 +166,15 @@ void main() async {

cachingAtServerFinder = CacheableSecondaryAddressFinder(
mockAtDirectoryHost, 64,
secondaryFinder:
SecondaryUrlFinder(mockAtDirectoryHost, 64, socketFactory: mockSocketFactory));
secondaryFinder: SecondaryUrlFinder(mockAtDirectoryHost, 64,
socketFactory: mockSocketFactory));

numSocketCreateCalls = 0;
when(() =>
mockSocketFactory.createSocket(mockAtDirectoryHost, '64', any()))
mockSocketFactory.createSocket(mockAtDirectoryHost, '64', any()))
.thenAnswer((invocation) {
print ('mock create socket: numFailures $numSocketCreateCalls requiredFailures $requiredFailures');
print(
'mock create socket: numFailures $numSocketCreateCalls requiredFailures $requiredFailures');
if (numSocketCreateCalls++ < requiredFailures) {
throw SocketException('Simulating socket connection failure');
} else {
Expand All @@ -191,44 +195,48 @@ void main() async {

when(() => mockSocket.write('$noAtAtSign\n'))
.thenAnswer((Invocation invocation) async {
socketOnDataFn("@$mockedAtServerAddress\n"
.codeUnits);
socketOnDataFn("@$mockedAtServerAddress\n".codeUnits);
});
});

test('test lookup of @alice with mocked atDirectory and zero failures', () async {
test('test lookup of @alice with mocked atDirectory and zero failures',
() async {
requiredFailures = 0;
SecondaryAddress sa = await cachingAtServerFinder.findSecondary(atSign);
expect(sa.toString(), mockedAtServerAddress);
expect(numSocketCreateCalls-1, requiredFailures);
expect(numSocketCreateCalls - 1, requiredFailures);
});

test('test lookup of @alice with mocked atDirectory and 1 failure', () async {
test('test lookup of @alice with mocked atDirectory and 1 failure',
() async {
requiredFailures = 1;
SecondaryAddress sa = await cachingAtServerFinder.findSecondary(atSign);
expect(sa.toString(), mockedAtServerAddress);
expect(numSocketCreateCalls-1, requiredFailures);
expect(numSocketCreateCalls - 1, requiredFailures);
});

test('test lookup of @alice with mocked atDirectory and 2 failures', () async {
test('test lookup of @alice with mocked atDirectory and 2 failures',
() async {
requiredFailures = 2;
SecondaryAddress sa = await cachingAtServerFinder.findSecondary(atSign);
expect(sa.toString(), mockedAtServerAddress);
expect(numSocketCreateCalls-1, requiredFailures);
expect(numSocketCreateCalls - 1, requiredFailures);
});

test('test lookup of @alice with mocked atDirectory and 3 failures', () async {
test('test lookup of @alice with mocked atDirectory and 3 failures',
() async {
requiredFailures = 3;
SecondaryAddress sa = await cachingAtServerFinder.findSecondary(atSign);
expect(sa.toString(), mockedAtServerAddress);
expect(numSocketCreateCalls-1, requiredFailures);
expect(numSocketCreateCalls - 1, requiredFailures);
});

test('test lookup of @alice with mocked atDirectory and 4 failures', () async {
test('test lookup of @alice with mocked atDirectory and 4 failures',
() async {
requiredFailures = 4;
SecondaryAddress sa = await cachingAtServerFinder.findSecondary(atSign);
expect(sa.toString(), mockedAtServerAddress);
expect(numSocketCreateCalls-1, requiredFailures);
expect(numSocketCreateCalls - 1, requiredFailures);
});

test('test lookup of @alice with mocked atDirectory and 5 failures',
Expand Down
2 changes: 2 additions & 0 deletions packages/at_onboarding_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 1.3.1
- build: require at_client 3.0.65 or above
## 1.3.0
- feat: Introduced verification-code based activation of atsigns
- fix: deprecate qr_code based activation
Expand Down
4 changes: 2 additions & 2 deletions packages/at_onboarding_cli/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_onboarding_cli
description: Dart tool to authenticate, onboard and perform complex operations on atSign seccondaries from command-line-interface.
version: 1.3.0
version: 1.3.1
repository: https://github.com/atsign-foundation/at_libraries
homepage: https://atsign.com
documentation: https://docs.atsign.com/
Expand All @@ -14,7 +14,7 @@ executables:

dependencies:
at_utils: ^3.0.12
at_client: ^3.0.59
at_client: ^3.0.65
at_lookup: ^3.0.36
zxing2: ^0.2.0
image: ^4.0.17
Expand Down

0 comments on commit 3cbaf2a

Please sign in to comment.