start of integration test

This commit is contained in:
Christien Rioux 2024-04-29 13:41:19 -04:00
parent 7e9254faac
commit 87735dfb8e
147 changed files with 5787 additions and 15 deletions

View file

@ -0,0 +1,39 @@
@Timeout(Duration(seconds: 60))
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'fixtures.dart';
import 'test_dht_record_pool.dart';
import 'test_dht_short_array.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
final fixture = DefaultFixture();
group('Started Tests', () {
setUpAll(fixture.setUp);
tearDownAll(fixture.tearDown);
// group('Crypto Tests', () {
// test('best cryptosystem', testBestCryptoSystem);
// test('get cryptosystem', testGetCryptoSystem);
// test('get cryptosystem invalid', testGetCryptoSystemInvalid);
// test('hash and verify password', testHashAndVerifyPassword);
// });
group('Attached Tests', () {
setUpAll(fixture.attach);
tearDownAll(fixture.detach);
group('DHT Support Tests', () {
group('DHTRecordPool Tests', () {
test('create pool', testDHTRecordPoolCreate);
});
group('DHTShortArray Tests', () {
test('create shortarray', testDHTShortArrayCreate);
});
});
});
});
}

View file

@ -0,0 +1,152 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:mutex/mutex.dart';
import 'package:veilid/veilid.dart';
class DefaultFixture {
DefaultFixture();
StreamSubscription<VeilidUpdate>? _veilidUpdateSubscription;
Stream<VeilidUpdate>? _veilidUpdateStream;
final StreamController<VeilidUpdate> _updateStreamController =
StreamController.broadcast();
static final _fixtureMutex = Mutex();
Future<void> setUp() async {
await _fixtureMutex.acquire();
assert(_veilidUpdateStream == null, 'should not set up fixture twice');
final ignoreLogTargetsStr =
// ignore: do_not_use_environment
const String.fromEnvironment('IGNORE_LOG_TARGETS').trim();
final ignoreLogTargets = ignoreLogTargetsStr.isEmpty
? <String>[]
: ignoreLogTargetsStr.split(',').map((e) => e.trim()).toList();
final Map<String, dynamic> platformConfigJson;
if (kIsWeb) {
final platformConfig = VeilidWASMConfig(
logging: VeilidWASMConfigLogging(
performance: VeilidWASMConfigLoggingPerformance(
enabled: true,
level: VeilidConfigLogLevel.debug,
logsInTimings: true,
logsInConsole: false,
ignoreLogTargets: ignoreLogTargets,
),
api: VeilidWASMConfigLoggingApi(
enabled: true,
level: VeilidConfigLogLevel.info,
ignoreLogTargets: ignoreLogTargets,
)));
platformConfigJson = platformConfig.toJson();
} else {
final platformConfig = VeilidFFIConfig(
logging: VeilidFFIConfigLogging(
terminal: VeilidFFIConfigLoggingTerminal(
enabled: false,
level: VeilidConfigLogLevel.debug,
ignoreLogTargets: ignoreLogTargets,
),
otlp: VeilidFFIConfigLoggingOtlp(
enabled: false,
level: VeilidConfigLogLevel.trace,
grpcEndpoint: 'localhost:4317',
serviceName: 'Veilid Tests',
ignoreLogTargets: ignoreLogTargets,
),
api: VeilidFFIConfigLoggingApi(
enabled: true,
// level: VeilidConfigLogLevel.debug,
level: VeilidConfigLogLevel.info,
ignoreLogTargets: ignoreLogTargets,
)));
platformConfigJson = platformConfig.toJson();
}
Veilid.instance.initializeVeilidCore(platformConfigJson);
var config = await getDefaultVeilidConfig(
isWeb: kIsWeb,
programName: 'Veilid Tests',
// ignore: avoid_redundant_argument_values, do_not_use_environment
bootstrap: const String.fromEnvironment('BOOTSTRAP'),
// ignore: avoid_redundant_argument_values, do_not_use_environment
networkKeyPassword: const String.fromEnvironment('NETWORK_KEY'),
);
config =
config.copyWith(tableStore: config.tableStore.copyWith(delete: true));
config = config.copyWith(
protectedStore: config.protectedStore.copyWith(delete: true));
config =
config.copyWith(blockStore: config.blockStore.copyWith(delete: true));
final us =
_veilidUpdateStream = await Veilid.instance.startupVeilidCore(config);
_veilidUpdateSubscription = us.listen((update) {
if (update is VeilidLog) {
// print(update.message);
} else if (update is VeilidUpdateAttachment) {
} else if (update is VeilidUpdateConfig) {
} else if (update is VeilidUpdateNetwork) {
} else if (update is VeilidAppMessage) {
} else if (update is VeilidAppCall) {
} else if (update is VeilidUpdateValueChange) {
} else if (update is VeilidUpdateRouteChange) {
} else {
throw Exception('unexpected update: $update');
}
_updateStreamController.sink.add(update);
});
}
Stream<VeilidUpdate> get updateStream => _updateStreamController.stream;
Future<void> attach() async {
await Veilid.instance.attach();
// Wait for attached state
while (true) {
final state = await Veilid.instance.getVeilidState();
var done = false;
if (state.attachment.publicInternetReady) {
switch (state.attachment.state) {
case AttachmentState.detached:
break;
case AttachmentState.attaching:
break;
case AttachmentState.detaching:
break;
default:
done = true;
break;
}
}
if (done) {
break;
}
await Future.delayed(const Duration(seconds: 1));
}
}
Future<void> detach() async {
await Veilid.instance.detach();
}
Future<void> tearDown() async {
assert(_veilidUpdateStream != null, 'should not tearDown without setUp');
final cancelFut = _veilidUpdateSubscription?.cancel();
await Veilid.instance.shutdownVeilidCore();
await cancelFut;
_veilidUpdateSubscription = null;
_veilidUpdateStream = null;
_fixtureMutex.release();
}
}

View file

@ -0,0 +1,9 @@
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:veilid_support/veilid_support.dart';
Future<void> testDHTRecordPoolCreate() async {
// final cs = await Veilid.instance.bestCryptoSystem();
// expect(await cs.defaultSaltLength(), equals(16));
}

View file

@ -0,0 +1,9 @@
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:veilid_support/veilid_support.dart';
Future<void> testDHTShortArrayCreate() async {
// final cs = await Veilid.instance.bestCryptoSystem();
// expect(await cs.defaultSaltLength(), equals(16));
}