Merge
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index 20aa3a6..87a1201 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -18,15 +18,7 @@
steps:
- uses: actions/checkout@v2
-
- - name: pub get
- run: pub get
-
- - name: dart format
- run: dart format --output=none --set-exit-if-changed .
-
- - name: dart analyze
- run: dart analyze
-
- - name: dart test
- run: dart test
+ - run: dart pub get
+ - run: dart format --output=none --set-exit-if-changed .
+ - run: dart analyze
+ - run: dart test
diff --git a/CHANGELOG.md b/CHANGELOG.md
index de81b95..87671bb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,10 @@
+## 4.0.2
+- Fix a bug with the analytics ping throttling algorithm.
+
+## 4.0.1
+- Force close the http client from `IOAnalytics.close()`.
+ This prevents lingering requests from making the application hang.
+
## 4.0.0
- Publishing a null safe stable release.
diff --git a/LICENSE b/LICENSE
index 5c60afe..000cd7b 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,5 @@
-Copyright 2014, the Dart project authors. All rights reserved.
+Copyright 2014, the Dart project authors.
+
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
@@ -9,7 +10,7 @@
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
- * Neither the name of Google Inc. nor the names of its
+ * Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
diff --git a/lib/src/usage_impl.dart b/lib/src/usage_impl.dart
index f3939b9..c1a0c81 100644
--- a/lib/src/usage_impl.dart
+++ b/lib/src/usage_impl.dart
@@ -44,10 +44,10 @@
}
void _checkReplenish() {
- var now = DateTime.now().millisecondsSinceEpoch;
+ final now = DateTime.now().millisecondsSinceEpoch;
- if (_lastReplenish + 1000 >= now) {
- var inc = (now - _lastReplenish) ~/ 1000;
+ if (_lastReplenish + 1000 < now) {
+ final inc = (now - _lastReplenish) ~/ 1000;
drops = math.min(drops + inc, startingCount);
_lastReplenish += (1000 * inc);
}
diff --git a/lib/src/usage_impl_io.dart b/lib/src/usage_impl_io.dart
index f4d257a..69dd392 100644
--- a/lib/src/usage_impl_io.dart
+++ b/lib/src/usage_impl_io.dart
@@ -6,8 +6,8 @@
import 'dart:convert' show JsonEncoder, jsonDecode;
import 'dart:io';
-import 'package:path/path.dart' as path;
import 'package:meta/meta.dart';
+import 'package:path/path.dart' as path;
import 'usage_impl.dart';
@@ -122,7 +122,11 @@
}
@override
- void close() => _client.close();
+ void close() {
+ // Do a force close to ensure that lingering requests will not stall the
+ // program.
+ _client.close(force: true);
+ }
}
JsonEncoder _jsonEncoder = JsonEncoder.withIndent(' ');
diff --git a/pubspec.yaml b/pubspec.yaml
index 42b2e18..a70557a 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -3,7 +3,7 @@
# BSD-style license that can be found in the LICENSE file.
name: usage
-version: 4.0.0
+version: 4.0.2
description: A Google Analytics wrapper for command-line, web, and Flutter apps.
homepage: https://github.com/dart-lang/usage
@@ -15,4 +15,4 @@
dev_dependencies:
pedantic: ^1.9.0
- test: ^1.16.0-nullsafety
+ test: ^1.16.0
diff --git a/test/usage_impl_test.dart b/test/usage_impl_test.dart
index 0d46125..21111b3 100644
--- a/test/usage_impl_test.dart
+++ b/test/usage_impl_test.dart
@@ -25,6 +25,18 @@
}
expect(bucket.removeDrop(), false);
});
+
+ test('does re-send after throttling', () async {
+ var bucket = ThrottlingBucket(20);
+ for (var i = 0; i < 20; i++) {
+ expect(bucket.removeDrop(), true);
+ }
+ expect(bucket.removeDrop(), false);
+
+ // TODO: Re-write to use package:fake_async.
+ await Future.delayed(Duration(milliseconds: 1500));
+ expect(bucket.removeDrop(), true);
+ });
});
group('AnalyticsImpl', () {