Merge pull request #49 from dukefirehawk/fix-bug/pr48

Fixed issue 48
This commit is contained in:
Thomas Hii 2022-01-23 13:14:59 +08:00 committed by GitHub
commit bab4e5eaf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 46 additions and 23 deletions

View file

@ -22,6 +22,24 @@ jobs:
- uses: dart-lang/setup-dart@v1 - uses: dart-lang/setup-dart@v1
with: with:
sdk: "2.15.1" sdk: "2.15.1"
- id: angel3_container_upgrade
name: angel3_container; Upgrade depedencies
working-directory: packages/container/angel_container
run: dart pub upgrade
- name: angel3_container; Verify formatting
working-directory: packages/container/angel_container
run: dart format --output=none --set-exit-if-changed .
# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: angel3_container; Analyze source code
working-directory: packages/container/angel_container
run: dart analyze
- name: angel3_container; Run tests
working-directory: packages/container/angel_container
run: dart test
- id: angel3_framework_upgrade - id: angel3_framework_upgrade
name: angel3_framework; Upgrade depedencies name: angel3_framework; Upgrade depedencies

View file

@ -26,11 +26,11 @@ void main() async {
CacheService( CacheService(
database: AnonymousService( database: AnonymousService(
index: ([params]) { index: ([params]) {
print('Fetched directly from the underlying service at ${new DateTime.now()}!'); print('Fetched directly from the underlying service at ${DateTime.now()}!');
return ['foo', 'bar', 'baz']; return ['foo', 'bar', 'baz'];
}, },
read: (id, [params]) { read: (id, [params]) {
return {id: '$id at ${new DateTime.now()}'}; return {id: '$id at ${DateTime.now()}'};
} }
), ),
), ),
@ -42,7 +42,7 @@ void main() async {
A flexible response cache for Angel3. A flexible response cache for Angel3.
Use this to improve real and perceived response of Web applications, as well as to memoize expensive responses. Use this to improve real and perceived response of Web applications, as well as to memorize expensive responses.
Supports the `If-Modified-Since` header, as well as storing the contents of response buffers in memory. Supports the `If-Modified-Since` header, as well as storing the contents of response buffers in memory.

View file

@ -7,7 +7,7 @@ import 'package:logging/logging.dart';
/// A flexible response cache for Angel. /// A flexible response cache for Angel.
/// ///
/// Use this to improve real and perceived response of Web applications, /// Use this to improve real and perceived response of Web applications,
/// as well as to memoize expensive responses. /// as well as to memorize expensive responses.
class ResponseCache { class ResponseCache {
/// A set of [Patterns] for which responses will be cached. /// A set of [Patterns] for which responses will be cached.
/// ///

View file

@ -23,11 +23,11 @@ class Container {
} }
/// Determines if the container has an injection of the given type. /// Determines if the container has an injection of the given type.
bool has<T>([Type? type]) { bool has<T>([Type? t]) {
var t2 = T; var t2 = T;
if (type != null) { if (t != null) {
t2 = type; t2 = t;
} else if (T == dynamic && type == null) { } else if (T == dynamic && t == null) {
return false; return false;
} }

View file

@ -1,5 +1,9 @@
# Change Log # Change Log
## 4.2.4
* Fixed issue 48. Log not working in development
## 4.2.3 ## 4.2.3
* Fixed `res.json()` throwing bad state exception * Fixed `res.json()` throwing bad state exception

View file

@ -4,7 +4,6 @@ import 'dart:io' show stderr, Cookie;
import 'package:angel3_http_exception/angel3_http_exception.dart'; import 'package:angel3_http_exception/angel3_http_exception.dart';
import 'package:angel3_route/angel3_route.dart'; import 'package:angel3_route/angel3_route.dart';
import 'package:belatuk_combinator/belatuk_combinator.dart'; import 'package:belatuk_combinator/belatuk_combinator.dart';
import 'package:logging/logging.dart';
import 'package:stack_trace/stack_trace.dart'; import 'package:stack_trace/stack_trace.dart';
import 'package:tuple/tuple.dart'; import 'package:tuple/tuple.dart';
import 'core.dart'; import 'core.dart';
@ -27,7 +26,7 @@ abstract class Driver<
bool isServerInitialised = false; bool isServerInitialised = false;
StreamSubscription<Request>? _sub; StreamSubscription<Request>? _sub;
final log = Logger('Driver'); //final log = Logger('Driver');
/// The function used to bind this instance to a server.. /// The function used to bind this instance to a server..
final Future<Server> Function(dynamic, int) serverGenerator; final Future<Server> Function(dynamic, int) serverGenerator;
@ -71,7 +70,7 @@ abstract class Driver<
return Future.value(_server); return Future.value(_server);
}); });
}).catchError((error) { }).catchError((error) {
log.severe('Failed to create server', error); app.logger?.severe('Failed to create server', error);
throw ArgumentError('[Driver]Failed to create server'); throw ArgumentError('[Driver]Failed to create server');
}); });
} }
@ -164,7 +163,7 @@ abstract class Driver<
..registerSingleton<ParseResult<RouteResult>?>(tuple.item3) ..registerSingleton<ParseResult<RouteResult>?>(tuple.item3)
..registerSingleton<ParseResult?>(tuple.item3); ..registerSingleton<ParseResult?>(tuple.item3);
if (app.environment.isProduction && app.logger != null) { if (!app.environment.isProduction && app.logger != null) {
req.container?.registerSingleton<Stopwatch>(Stopwatch()..start()); req.container?.registerSingleton<Stopwatch>(Stopwatch()..start());
} }
@ -250,7 +249,7 @@ abstract class Driver<
// Ideally, we won't be in a position where an absolutely fatal error occurs, // Ideally, we won't be in a position where an absolutely fatal error occurs,
// but if so, we'll need to log it. // but if so, we'll need to log it.
if (app.logger != null) { if (app.logger != null) {
app.logger?.severe( app.logger!.severe(
'Fatal error occurred when processing $uri.', e, trace); 'Fatal error occurred when processing $uri.', e, trace);
} else { } else {
stderr stderr
@ -323,7 +322,7 @@ abstract class Driver<
ResponseContext res, ResponseContext res,
{bool ignoreFinalizers = false}) { {bool ignoreFinalizers = false}) {
Future<void> _cleanup(_) { Future<void> _cleanup(_) {
if (app.environment.isProduction && if (!app.environment.isProduction &&
app.logger != null && app.logger != null &&
req.container!.has<Stopwatch>()) { req.container!.has<Stopwatch>()) {
var sw = req.container!.make<Stopwatch>(); var sw = req.container!.make<Stopwatch>();
@ -334,11 +333,10 @@ abstract class Driver<
} }
if (!res.isBuffered) { if (!res.isBuffered) {
if (res.isOpen) { //if (res.isOpen) {
return res.close().then(_cleanup); return res.close().then(_cleanup);
} //}
//return Future.value();
return Future.value();
} }
var finalizers = ignoreFinalizers == true var finalizers = ignoreFinalizers == true

View file

@ -1,5 +1,5 @@
name: angel3_framework name: angel3_framework
version: 4.2.3 version: 4.2.4
description: A high-powered HTTP server extensible framework with dependency injection, routing and much more. description: A high-powered HTTP server extensible framework with dependency injection, routing and much more.
homepage: https://angel3-framework.web.app/ homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel/tree/master/packages/framework repository: https://github.com/dukefirehawk/angel/tree/master/packages/framework
@ -35,3 +35,6 @@ dev_dependencies:
io: ^1.0.0 io: ^1.0.0
test: ^1.17.5 test: ^1.17.5
lints: ^1.0.0 lints: ^1.0.0
dependency_overrides:
angel3_container:
path: ../container/angel_container

View file

@ -22,7 +22,7 @@ Future<void> plaintext(var message) async {
var url = Uri.http('localhost:3000', '/plaintext'); var url = Uri.http('localhost:3000', '/plaintext');
var response = await http.get(url); var response = await http.get(url);
if (response.statusCode == 200) { if (response.statusCode == 200) {
print('Execution($message): success'); print('Execution($message): ${response.body}.');
} else { } else {
print('Execution($message): error'); print('Execution($message): error');
} }
@ -92,10 +92,10 @@ Future<void> dbMultipleQuery(var message) async {
} }
void main() async { void main() async {
var concurrency = 100; var concurrency = 6000;
for (var i = 0; i < concurrency; i++) { for (var i = 0; i < concurrency; i++) {
Isolate.spawn(dbUpdate, 'Instance_$i'); Isolate.spawn(plaintext, 'Instance_$i');
} }
await Future.delayed(const Duration(seconds: 10)); await Future.delayed(const Duration(seconds: 10));