Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscriber Connectivity Tests #924

Merged
merged 56 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
6cd7c7c
Add testing boilerplate
AndyTWF Jan 18, 2023
291af3a
WIP: location updates arrive after resolution test
AndyTWF Jan 18, 2023
aa98b82
Apply proper publish channel mode in test
AndyTWF Jan 18, 2023
9470126
Tidy up styling
AndyTWF Jan 18, 2023
58efd8c
Add tests for publisher presence
AndyTWF Jan 19, 2023
327b07a
Merge remote-tracking branch 'origin/main' into 918-susbscriber-conne…
AndyTWF Jan 19, 2023
b08b2ce
Resolve todo comments
AndyTWF Jan 19, 2023
b3abad1
Refactor repeated code into helper methods
AndyTWF Jan 19, 2023
32fc53c
Fix linting
AndyTWF Jan 19, 2023
8a848aa
Fix linting issues
AndyTWF Jan 19, 2023
5477932
Enable other test cases
AndyTWF Jan 19, 2023
d2ffb59
Emulate action uploads build reports for subscribing SDK
AndyTWF Jan 19, 2023
ca9960e
bump ably connect timeout for testing purposes
AndyTWF Jan 19, 2023
2c3d3a6
Use repeatable subscriber shutdown method
AndyTWF Jan 19, 2023
9126294
Skip connectivity tests on API level 21
AndyTWF Jan 20, 2023
1ec63ea
Revert "bump ably connect timeout for testing purposes"
AndyTWF Jan 20, 2023
062db92
Use ably-android as a test implementation
AndyTWF Jan 20, 2023
25b472a
Only check for channel online once
AndyTWF Jan 20, 2023
82c93d8
Add cooling off period for L7 proxy in tests
AndyTWF Jan 20, 2023
dc1f3bb
Try increasing grace period
AndyTWF Jan 20, 2023
27fa85e
Add test for resolution updates
AndyTWF Jan 23, 2023
57ca67b
Add test for subscriber resolution preference updates
AndyTWF Jan 23, 2023
a6f43e3
Comment out test cases for now
AndyTWF Jan 23, 2023
9b19ac8
Add subscriber-specific test skip
AndyTWF Jan 23, 2023
55ade0b
Rename publisher skip test property
AndyTWF Jan 23, 2023
fd24b00
Update comment
AndyTWF Jan 23, 2023
68ba90e
Merge pull request #932 from ably/918-additional-tests
AndyTWF Jan 23, 2023
f73476d
Merge remote-tracking branch 'origin/main' into 918-susbscriber-conne…
AndyTWF Jan 23, 2023
850a1d5
WIP: Moving to state transition helpers in tests
AndyTWF Jan 24, 2023
058c6d4
Merge remote-tracking branch 'origin/main' into 918-susbscriber-conne…
AndyTWF Jan 25, 2023
6bbe745
Migrate subscriber resoltion updates to state transition code
AndyTWF Jan 25, 2023
f404eba
Merge remote-tracking branch 'origin/main' into 918-susbscriber-conne…
AndyTWF Jan 25, 2023
ed2e372
Merge remote-tracking branch 'origin/main' into 918-susbscriber-conne…
AndyTWF Jan 26, 2023
ab86771
Fix linting and style issues
AndyTWF Jan 26, 2023
f416284
remove unused import
AndyTWF Jan 26, 2023
dc58386
Merge remote-tracking branch 'origin/main' into 918-susbscriber-conne…
AndyTWF Jan 31, 2023
a1d1153
Merge remote-tracking branch 'origin/main' into 918-susbscriber-conne…
AndyTWF Jan 31, 2023
c042f77
Update faults that are skipped
AndyTWF Jan 31, 2023
4a68198
Fix lint issue
AndyTWF Jan 31, 2023
b293058
Merge remote-tracking branch 'origin/main' into 918-susbscriber-conne…
AndyTWF Feb 9, 2023
7346609
Handle changes to publisher since last merge
AndyTWF Feb 9, 2023
89c66ed
Unskip more faults
AndyTWF Feb 9, 2023
13868a5
Test side effects in before starting tests
AndyTWF Feb 9, 2023
f406663
Test for side effects
AndyTWF Feb 9, 2023
db55c56
Lint and more checks
AndyTWF Feb 9, 2023
bc94339
Reskip flakey hanging tests
AndyTWF Feb 9, 2023
42c17f0
Merge branch 'main' into 918-susbscriber-connectivity-tests
AndyTWF Feb 10, 2023
471ecb2
Merge branch 'main' into 918-susbscriber-connectivity-tests
AndyTWF Feb 10, 2023
57cc80d
Use withTestResources in tests
AndyTWF Feb 10, 2023
7a00d1f
Introduce suspending version of Ably.sendEnhancedLocationUpdate
AndyTWF Feb 10, 2023
6cef61b
Style fixes
AndyTWF Feb 10, 2023
f63aee5
Remove runBlocking
AndyTWF Feb 14, 2023
583c4d6
lint
AndyTWF Feb 14, 2023
f628ed8
Merge branch 'main' into 918-susbscriber-connectivity-tests
AndyTWF Feb 14, 2023
b335619
Stop using deprecated subscriber method
AndyTWF Feb 14, 2023
9f87735
linting
AndyTWF Feb 14, 2023
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
7 changes: 7 additions & 0 deletions .github/workflows/emulate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ jobs:
with:
name: api-level-${{ matrix.api-level }}-publishing-sdk-build-reports
path: publishing-sdk/build/reports

- uses: actions/upload-artifact@v3
name: Build Reports for subscribing-sdk
if: always()
with:
name: api-level-${{ matrix.api-level }}-subscribing-sdk-build-reports
path: subscribing-sdk/build/reports
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ private const val REALTIME_HOST = "realtime.ably.io"
private const val REALTIME_PORT = 443

const val PUBLISHER_CLIENT_ID = "AatNetworkConnectivityTests_Publisher"
const val SUBSCRIBER_CLIENT_ID = "AatNetworkConnectivityTests_Subscriber"

/**
* A local proxy that can be used to intercept Realtime traffic for testing
Expand Down Expand Up @@ -310,6 +311,7 @@ class Layer7Proxy(
override fun stop() {
testLogD("$tag: stopping...")
server?.stop()
testLogD("$tag: done stopping...")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ abstract class FaultSimulation {
* The advantage of this approach is that the test code remains active and continually compiled as
* a first class citizen of the codebase, while we work on other things to get it passing.
*/
open val skipTest: Boolean = false
open val skipPublisherTest: Boolean = false

// Causes the same behaviour as skipPublisherTest for the subscriber NetworkConnectivityTests
open val skipSubscriberTest: Boolean = false

/**
* A RealtimeProxy instance that will be manipulated by this fault
Expand Down Expand Up @@ -162,6 +165,9 @@ class TcpConnectionRefused(apiKey: String) : TransportLayerFault(apiKey) {
onlineWithinMillis = 60_000
)

// May be able to be removed once the issues surrounding skipTest are resolved
override val skipSubscriberTest = true

override fun enable() {
tcpProxy.stop()
}
Expand All @@ -177,6 +183,8 @@ class TcpConnectionRefused(apiKey: String) : TransportLayerFault(apiKey) {
*/
class TcpConnectionUnresponsive(apiKey: String) : TransportLayerFault(apiKey) {

override val skipSubscriberTest = true

companion object {
val fault = object : Fault() {
override fun simulate(apiKey: String) = TcpConnectionUnresponsive(apiKey)
Expand Down Expand Up @@ -212,6 +220,9 @@ class DisconnectAndSuspend(apiKey: String) : TransportLayerFault(apiKey) {
}
}

// May be able to be removed once the issues surrounding skipTest are resolved
override val skipSubscriberTest = true

private val timer = Timer()

override val type = FaultType.Nonfatal(
Expand Down Expand Up @@ -445,6 +456,8 @@ class EnterUnresponsive(apiKey: String) : UnresponsiveAfterAction(
direction = FrameDirection.ClientToServer,
action = Message.Action.PRESENCE
) {
override val skipSubscriberTest = true

companion object {
val fault = object : Fault() {
override fun simulate(apiKey: String) = EnterUnresponsive(apiKey)
Expand All @@ -462,7 +475,6 @@ class EnterUnresponsive(apiKey: String) : UnresponsiveAfterAction(
* Publisher should continue regardless.
*/
class DisconnectWithFailedResume(apiKey: String) : ApplicationLayerFault(apiKey) {

companion object {
val fault = object : Fault() {
override fun simulate(apiKey: String) = DisconnectWithFailedResume(apiKey)
Expand Down Expand Up @@ -620,6 +632,9 @@ class EnterFailedWithNonfatalNack(apiKey: String) : PresenceNackFault(
}
}

// Can probably be removed once skipTest issues are resolved
override val skipSubscriberTest = true

override val type = FaultType.Nonfatal(
resolvedWithinMillis = 60_000L
)
Expand All @@ -642,6 +657,8 @@ class UpdateFailedWithNonfatalNack(apiKey: String) : PresenceNackFault(
}
}

override val skipSubscriberTest = true

override val type = FaultType.Nonfatal(
resolvedWithinMillis = 60_000L
)
Expand All @@ -655,6 +672,8 @@ class UpdateFailedWithNonfatalNack(apiKey: String) : PresenceNackFault(
*/
class ReenterOnResumeFailed(apiKey: String) : ApplicationLayerFault(apiKey) {

override val skipSubscriberTest = true

companion object {
val fault = object : Fault() {
override fun simulate(apiKey: String) = ReenterOnResumeFailed(apiKey)
Expand Down
26 changes: 26 additions & 0 deletions common/src/main/java/com/ably/tracking/common/Ably.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ interface Ably {
callback: (Result<Unit>) -> Unit
)

/**
* Sends an enhanced location update to the channel in a suspending fashion.
* Should be called only when there's an existing channel for the [trackableId].
* If a channel for the [trackableId] doesn't exist then it just returns.
*
* @param trackableId The ID of the trackable channel.
* @param locationUpdate The location update that is sent to the channel.
*/
suspend fun sendEnhancedLocationSuspending(trackableId: String, locationUpdate: EnhancedLocationUpdate)

/**
* Sends a raw location update to the channel.
* Should be called only when there's an existing channel for the [trackableId].
Expand Down Expand Up @@ -557,6 +567,22 @@ constructor(
}
}

override suspend fun sendEnhancedLocationSuspending(trackableId: String, locationUpdate: EnhancedLocationUpdate) {
logHandler?.d("$TAG sendEnhancedLocationMessageSuspending: publishing")
suspendCancellableCoroutine { continuation ->
sendEnhancedLocation(
trackableId,
locationUpdate,
) { result ->
try {
continuation.resume(result.getOrThrow())
} catch (exception: Exception) {
continuation.resumeWithException(exception)
}
}
}
}

override fun sendEnhancedLocation(
trackableId: String,
locationUpdate: EnhancedLocationUpdate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class NetworkConnectivityTests(private val testFault: Fault) {
@Before
fun setUp() {
val simulation = testFault.simulate(BuildConfig.ABLY_API_KEY)
Assume.assumeFalse(simulation.skipTest)
Assume.assumeFalse(simulation.skipPublisherTest)

// We cannot use ktor on API Level 21 (Lollipop) because of:
// https://youtrack.jetbrains.com/issue/KTOR-4751/HttpCache-plugin-uses-ConcurrentMap.computeIfAbsent-method-that-is-available-only-since-Android-API-24
Expand Down
1 change: 1 addition & 0 deletions subscribing-sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ android {
dependencies {
api project(':core-sdk')
implementation project(':common')
androidTestImplementation "io.ably:ably-android:$ably_core_version"
}

ext {
Expand Down
Loading