Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## XX.XX.XX
* Added a new function "addCustomNetworkRequestHeaders: customHeaderValues" for providing or overriding custom headers after init.
* Added "setRequestTimeoutDuration(requestTimeoutDuration)" init config method to change request timeout duration in seconds.
* Default request method is now set to "POST"
* Added a new function "recordMetrics: metricsOverride" to send a device metrics request.
* Added a new Consent option "metrics" for controlling "recordMetrics" method. (This has no effect on Session metrics.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,10 @@ private void populateConfig(JSONObject _config) throws JSONException {
this.config.setRequestDropAgeHours(_config.getInt("requestDropAgeHours"));
}

if (_config.has("requestTimeoutDuration")) {
this.config.setRequestTimeoutDuration(_config.getInt("requestTimeoutDuration"));
}

if (_config.has("manualSessionEnabled") && _config.getBoolean("manualSessionEnabled")) {
enableManualSessionControl();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:countly_flutter/countly_flutter.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../utils.dart';

/// Tests for the requestTimeoutDuration configuration option default value.
/// Verifies that the SDK initializes correctly with the default option
/// and that requests are attempted.
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('requestTimeoutDuration_default_test', (WidgetTester tester) async {
// Create a server that delays response by 3 seconds
List<Map<String, List<String>>> requestArray = <Map<String, List<String>>>[];
createServer(requestArray, delay: 3);

// Initialize SDK with default request timeout
CountlyConfig config = CountlyConfig('http://0.0.0.0:8080', APP_KEY).enableManualSessionHandling().setLoggingEnabled(true); // Use default timeout

await Countly.initWithConfig(config);

// Start a session to trigger a request
await Countly.instance.sessions.beginSession();

// Wait for a bit to allow the request to be processed
await Future.delayed(const Duration(seconds: 5));

List<String> requestList = await getRequestQueue();
equals(requestList.length, 0);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:countly_flutter/countly_flutter.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import '../utils.dart';
import '../views_tests/auto_view_flow1_test.dart';

/// Tests for the requestTimeoutDuration configuration option.
/// Verifies that the SDK initializes correctly with the option set
/// and that requests are attempted.
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('requestTimeoutDuration_test', (WidgetTester tester) async {
// Create a server that delays response by 3 seconds
// This is longer than the timeout we will set (1 second)
List<Map<String, List<String>>> requestArray = <Map<String, List<String>>>[];
createServer(requestArray, delay: 3);

// Initialize SDK with a short request timeout
CountlyConfig config = CountlyConfig('http://0.0.0.0:8080', APP_KEY).enableManualSessionHandling().setLoggingEnabled(true).setRequestTimeoutDuration(1); // Set timeout to 1 second

await Countly.initWithConfig(config);

// Start a session to trigger a request
await Countly.instance.sessions.beginSession();

// Wait for a bit to allow the request to be processed
await Future.delayed(const Duration(seconds: 5));

// Verify that we at least attempted to send requests but they timed out thus remained in the queue
List<String> requestList = await getRequestQueue();

// Check if the begin_session request in the queue
equals(requestList.length, 1);
validateBeginSessionRequest(requestList[0]);
});
}
1 change: 1 addition & 0 deletions example/lib/config_object.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class CountlyConfiguration {
// ..setParameterTamperingProtectionSalt('salt') // Set the optional salt to be used for calculating the checksum of requested data which will be sent with each request
// ..enableManualSessionHandling() // Enable manual session handling
// ..setHttpPostForced(true) // Set to 'false' if you want HTTP POST not to be used for all requests
// ..setRequestTimeoutDuration(15) // Set the request timeout duration to 15 seconds
// ..setCustomNetworkRequestHeaders({
// 'Content-Type': 'application/json',
// 'Authorization': 'Bearer YOUR_ACCESS_TOKEN',
Expand Down
5 changes: 5 additions & 0 deletions ios/Classes/CountlyFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,11 @@ - (void)populateConfig:(NSDictionary *)_config {
config.requestDropAgeHours = [requestDropAgeHours intValue];
}

NSNumber *requestTimeoutDuration = _config[@"requestTimeoutDuration"];
if (requestTimeoutDuration) {
config.requestTimeoutDuration = [requestTimeoutDuration intValue];
}

NSNumber *manualSessionEnabled = _config[@"manualSessionEnabled"];
if (manualSessionEnabled && [manualSessionEnabled boolValue]) {
config.manualSessionHandling = YES;
Expand Down
10 changes: 10 additions & 0 deletions lib/src/countly_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CountlyConfig {
String? _sdkBehaviorSettings;
bool _backoffMechanismDisabled = false;
bool _sdkBehaviorSettingsUpdatesDisabled = false;
int? _requestTimeoutDuration;

/// instance of CountlyConfigApm
final CountlyConfigApm _countlyConfigApmInstance = CountlyConfigApm();
Expand Down Expand Up @@ -143,6 +144,8 @@ class CountlyConfig {

bool get sdkBehaviorSettingsUpdatesDisabled => _sdkBehaviorSettingsUpdatesDisabled;

int? get requestTimeoutDuration => _requestTimeoutDuration;

/// getter for CountlyConfigApm instance that is used to access CountlyConfigApm methods
CountlyConfigApm get apm => _countlyConfigApmInstance;

Expand Down Expand Up @@ -401,4 +404,11 @@ class CountlyConfig {
_sdkBehaviorSettingsUpdatesDisabled = true;
return this;
}

/// Set the request timeout duration in seconds
/// [int requestTimeoutDuration] - duration in seconds
CountlyConfig setRequestTimeoutDuration(int requestTimeoutDuration) {
_requestTimeoutDuration = requestTimeoutDuration;
return this;
}
}
5 changes: 5 additions & 0 deletions lib/src/countly_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,11 @@ class Countly {

log('"_configToJson", value provided for remoteConfigValueCaching: [${config.remoteConfigValueCaching}]', logLevel: LogLevel.INFO);
countlyConfig['remoteConfigValueCaching'] = config.remoteConfigValueCaching;

if (config.requestTimeoutDuration != null) {
log('"_configToJson", value provided for requestTimeoutDuration: [${config.requestTimeoutDuration}]', logLevel: LogLevel.INFO);
countlyConfig['requestTimeoutDuration'] = config.requestTimeoutDuration;
}
} catch (e) {
log('"_configToJson", Exception occur during converting config to json: $e', logLevel: LogLevel.ERROR);
}
Expand Down