update ndk and gradle versions

add subpackage to veilid-flutter with test fixtures for writing veilid integration tests in dart
This commit is contained in:
Christien Rioux 2024-04-30 17:43:09 -04:00
parent bcacaeb300
commit bcee358a0e
20 changed files with 305 additions and 80 deletions

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip

View File

@ -1,9 +1,15 @@
include: package:flutter_lints/flutter.yaml
include: package:lint_hard/all.yaml
analyzer:
errors:
invalid_annotation_target: ignore
exclude:
- '**/*.g.dart'
- '**/*.freezed.dart'
- '**/*.pb.dart'
- '**/*.pbenum.dart'
- '**/*.pbjson.dart'
- '**/*.pbserver.dart'
linter:
rules:
- unawaited_futures
unawaited_futures: true
avoid_positional_boolean_parameters: false

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip

View File

@ -1,9 +1,11 @@
@Timeout(Duration(seconds: 60))
library veilid_flutter_integration_test;
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:veilid_test/veilid_test.dart';
import 'fixtures.dart';
import 'test_crypto.dart';
import 'test_routing_context.dart';
import 'test_table_db.dart';
@ -12,7 +14,8 @@ import 'test_dht.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
final fixture = DefaultFixture();
final fixture =
DefaultVeilidFixture(programName: 'veilid_flutter integration test');
group('Unstarted Tests', () {
test('veilid config defaults', testVeilidConfigDefaults);

View File

@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:veilid/veilid.dart';
import 'package:loggy/loggy.dart';
import 'package:ansicolor/ansicolor.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:loggy/loggy.dart';
import 'package:veilid/veilid.dart';
// Loggy tools
const LogLevel traceLevel = LogLevel('Trace', 1);
@ -86,24 +86,23 @@ class CallbackPrinter extends LoggyPrinter {
callback?.call(record);
}
void setCallback(Function(LogRecord)? cb) {
// ignore: use_setters_to_change_properties
void setCallback(void Function(LogRecord)? cb) {
callback = cb;
}
}
var globalTerminalPrinter = CallbackPrinter();
CallbackPrinter globalTerminalPrinter = CallbackPrinter();
extension TraceLoggy on Loggy {
void trace(dynamic message, [Object? error, StackTrace? stackTrace]) =>
log(traceLevel, message, error, stackTrace);
}
LogOptions getLogOptions(LogLevel? level) {
return LogOptions(
level ?? LogLevel.all,
stackTraceLevel: LogLevel.error,
);
}
LogOptions getLogOptions(LogLevel? level) => LogOptions(
level ?? LogLevel.all,
stackTraceLevel: LogLevel.error,
);
void initLoggy() {
Loggy.initLoggy(

View File

@ -6,7 +6,6 @@ import 'veilid_theme.dart';
const kDefaultTerminalStyle = TerminalStyle(
fontSize: kDefaultMonoTerminalFontSize,
height: kDefaultMonoTerminalFontHeight,
fontFamily: kDefaultMonoTerminalFontFamily);
class LogTerminal extends StatefulWidget {
@ -14,7 +13,7 @@ class LogTerminal extends StatefulWidget {
@override
// ignore: library_private_types_in_public_api
_LogTerminalState createState() => _LogTerminalState();
State<LogTerminal> createState() => _LogTerminalState();
}
class _LogTerminalState extends State<LogTerminal> {
@ -28,32 +27,31 @@ class _LogTerminalState extends State<LogTerminal> {
void initState() {
super.initState();
terminal.setLineFeedMode(true);
globalTerminalPrinter
.setCallback((log) => {terminal.write("${log.pretty()}\n")});
globalTerminalPrinter.setCallback((log) {
terminal.write('${log.pretty()}\n');
});
}
@override
Widget build(BuildContext context) {
return TerminalView(
terminal,
textStyle: kDefaultTerminalStyle,
controller: terminalController,
autofocus: true,
backgroundOpacity: 0.9,
onSecondaryTapDown: (details, offset) async {
final selection = terminalController.selection;
if (selection != null) {
final text = terminal.buffer.getText(selection);
terminalController.clearSelection();
await Clipboard.setData(ClipboardData(text: text));
} else {
final data = await Clipboard.getData('text/plain');
final text = data?.text;
if (text != null) {
terminal.paste(text);
Widget build(BuildContext context) => TerminalView(
terminal,
textStyle: kDefaultTerminalStyle,
controller: terminalController,
autofocus: true,
backgroundOpacity: 0.9,
onSecondaryTapDown: (details, offset) async {
final selection = terminalController.selection;
if (selection != null) {
final text = terminal.buffer.getText(selection);
terminalController.clearSelection();
await Clipboard.setData(ClipboardData(text: text));
} else {
final data = await Clipboard.getData('text/plain');
final text = data?.text;
if (text != null) {
terminal.paste(text);
}
}
}
},
);
}
},
);
}

View File

@ -17,6 +17,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
async_tools:
dependency: transitive
description:
name: async_tools
sha256: "972f68ab663724d86260a31e363c1355ff493308441b872bf4e7b8adc67c832c"
url: "https://pub.dev"
source: hosted
version: "0.1.0"
boolean_selector:
dependency: transitive
description:
@ -139,14 +147,6 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description:
name: flutter_lints
sha256: e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
url: "https://pub.dev"
source: hosted
version: "3.0.1"
flutter_test:
dependency: "direct dev"
description: flutter
@ -215,14 +215,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.1"
lints:
dependency: transitive
lint_hard:
dependency: "direct dev"
description:
name: lints
sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
name: lint_hard
sha256: "44d15ec309b1a8e1aff99069df9dcb1597f49d5f588f32811ca28fb7b38c32fe"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "4.0.0"
loggy:
dependency: "direct main"
description:
@ -263,14 +263,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.11.0"
mutex:
dependency: "direct dev"
description:
name: mutex
sha256: "8827da25de792088eb33e572115a5eb0d61d61a3c01acbc8bcbe76ed78f1a1f2"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
path:
dependency: "direct main"
description:
@ -459,6 +451,13 @@ packages:
relative: true
source: path
version: "0.3.1"
veilid_test:
dependency: "direct dev"
description:
path: "../packages/veilid_test"
relative: true
source: path
version: "0.1.0"
vm_service:
dependency: transitive
description:
@ -508,5 +507,5 @@ packages:
source: hosted
version: "0.0.6"
sdks:
dart: ">=3.3.0 <4.0.0"
dart: ">=3.3.4 <4.0.0"
flutter: ">=3.19.1"

View File

@ -44,8 +44,10 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter
flutter_lints: ^3.0.1
mutex: ^3.1.0
lint_hard: ^4.0.0
veilid_test:
path: ../packages/veilid_test
# The following section is specific to Flutter.
flutter:

View File

@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

View File

@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

View File

@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

View File

@ -0,0 +1,15 @@
include: package:lint_hard/all.yaml
analyzer:
errors:
invalid_annotation_target: ignore
exclude:
- '**/*.g.dart'
- '**/*.freezed.dart'
- '**/*.pb.dart'
- '**/*.pbenum.dart'
- '**/*.pbjson.dart'
- '**/*.pbserver.dart'
linter:
rules:
unawaited_futures: true
avoid_positional_boolean_parameters: false

View File

@ -0,0 +1,21 @@
import 'package:veilid/veilid.dart';
class ProcessorConnectionState {
ProcessorConnectionState();
VeilidStateAttachment attachment = const VeilidStateAttachment(
localNetworkReady: false,
publicInternetReady: false,
state: AttachmentState.detached);
VeilidStateNetwork network = VeilidStateNetwork(
bpsDown: BigInt.from(0),
bpsUp: BigInt.from(0),
started: false,
peers: []);
bool get isAttached => !(attachment.state == AttachmentState.detached ||
attachment.state == AttachmentState.detaching ||
attachment.state == AttachmentState.attaching);
bool get isPublicInternetReady => attachment.publicInternetReady;
}

View File

@ -0,0 +1,47 @@
import 'dart:async';
import 'package:async_tools/async_tools.dart';
import 'update_processor_fixture.dart';
abstract class TickerFixtureTickable {
Future<void> onTick();
}
class TickerFixture {
TickerFixture({required this.updateProcessorFixture});
static final _fixtureMutex = Mutex();
UpdateProcessorFixture updateProcessorFixture;
Timer? _tickTimer;
final List<TickerFixtureTickable> _tickables = [];
Future<void> setUp() async {
await _fixtureMutex.acquire();
_tickTimer = Timer.periodic(const Duration(seconds: 1), (timer) {
singleFuture(this, _onTick);
});
}
Future<void> tearDown() async {
assert(_fixtureMutex.isLocked, 'should not tearDown without setUp');
final tickTimer = _tickTimer;
if (tickTimer != null) {
tickTimer.cancel();
}
_fixtureMutex.release();
}
void register(TickerFixtureTickable tickable) {
_tickables.add(tickable);
}
void unregister(TickerFixtureTickable tickable) {
_tickables.remove(tickable);
}
Future<void> _onTick() async {
await _tickables.map((t) => t.onTick()).wait;
}
}

View File

@ -0,0 +1,42 @@
import 'dart:async';
import 'package:async_tools/async_tools.dart';
import 'package:veilid/veilid.dart';
import 'processor_connection_state.dart';
import 'veilid_fixture.dart';
class UpdateProcessorFixture {
UpdateProcessorFixture({required this.veilidFixture});
static final _fixtureMutex = Mutex();
VeilidFixture veilidFixture;
ProcessorConnectionState processorConnectionState =
ProcessorConnectionState();
Future<void> setUp() async {
await _fixtureMutex.acquire();
veilidFixture.updateStream.listen((update) {
if (update is VeilidUpdateNetwork) {
processorConnectionState.network = processorConnectionState.network =
VeilidStateNetwork(
started: update.started,
bpsDown: update.bpsDown,
bpsUp: update.bpsUp,
peers: update.peers);
} else if (update is VeilidUpdateAttachment) {
processorConnectionState.attachment = VeilidStateAttachment(
state: update.state,
publicInternetReady: update.publicInternetReady,
localNetworkReady: update.localNetworkReady);
}
});
}
Future<void> tearDown() async {
assert(_fixtureMutex.isLocked, 'should not tearDown without setUp');
_fixtureMutex.release();
}
}

View File

@ -1,11 +1,20 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:mutex/mutex.dart';
import 'package:async_tools/async_tools.dart';
import 'package:veilid/veilid.dart';
class DefaultFixture {
DefaultFixture();
bool kIsWeb = bool.fromEnvironment('dart.library.js_util');
abstract class VeilidFixture {
Future<void> setUp();
Future<void> tearDown();
Future<void> attach();
Future<void> detach();
Stream<VeilidUpdate> get updateStream;
}
class DefaultVeilidFixture implements VeilidFixture {
DefaultVeilidFixture({required this.programName});
StreamSubscription<VeilidUpdate>? _veilidUpdateSubscription;
Stream<VeilidUpdate>? _veilidUpdateStream;
@ -13,7 +22,9 @@ class DefaultFixture {
StreamController.broadcast();
static final _fixtureMutex = Mutex();
final String programName;
@override
Future<void> setUp() async {
await _fixtureMutex.acquire();
@ -70,7 +81,7 @@ class DefaultFixture {
var config = await getDefaultVeilidConfig(
isWeb: kIsWeb,
programName: 'Veilid Tests',
programName: programName,
// ignore: avoid_redundant_argument_values, do_not_use_environment
bootstrap: const String.fromEnvironment('BOOTSTRAP'),
// ignore: avoid_redundant_argument_values, do_not_use_environment
@ -104,8 +115,10 @@ class DefaultFixture {
});
}
@override
Stream<VeilidUpdate> get updateStream => _updateStreamController.stream;
@override
Future<void> attach() async {
await Veilid.instance.attach();
@ -121,7 +134,11 @@ class DefaultFixture {
break;
case AttachmentState.detaching:
break;
default:
case AttachmentState.attachedGood:
case AttachmentState.attachedStrong:
case AttachmentState.attachedWeak:
case AttachmentState.overAttached:
case AttachmentState.fullyAttached:
done = true;
break;
}
@ -129,16 +146,18 @@ class DefaultFixture {
if (done) {
break;
}
await Future.delayed(const Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
}
}
@override
Future<void> detach() async {
await Veilid.instance.detach();
}
@override
Future<void> tearDown() async {
assert(_veilidUpdateStream != null, 'should not tearDown without setUp');
assert(_fixtureMutex.isLocked, 'should not tearDown without setUp');
final cancelFut = _veilidUpdateSubscription?.cancel();
await Veilid.instance.shutdownVeilidCore();

View File

@ -0,0 +1,7 @@
/// Support testing Veilid applications
library;
export 'src/processor_connection_state.dart';
export 'src/ticker_fixture.dart';
export 'src/update_processor_fixture.dart';
export 'src/veilid_fixture.dart';

View File

@ -0,0 +1,18 @@
name: veilid_test
description: A library for testing Veilid applications
version: 0.1.0
publish_to: none
# repository: https://gitlab.com/veilid/dart_veilid_test
environment:
sdk: ^3.3.4
# Add regular dependencies here.
dependencies:
async_tools: ^0.1.0
veilid:
path: ../..
dev_dependencies:
lint_hard: ^4.0.0
test: ^1.24.0

View File

@ -1,6 +1,6 @@
#Mon Nov 28 22:38:53 EST 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME