Skip to content

Commit

Permalink
style: run dart format in at_lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
gkc committed Sep 15, 2023
1 parent a1ffec7 commit 47d225d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 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

0 comments on commit 47d225d

Please sign in to comment.