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

Setup AnalyticEventCallbackRule for DefaultEventReporterTest #10575

Merged
merged 1 commit into from
Apr 7, 2025

Conversation

cttsai-stripe
Copy link
Contributor

Summary

Use a TestWatcher to wrap up the callback provider initialization and the turbine clean up.

Motivation

To prevent duplicate callback initializing when adding more tests

Testing

  • Added tests
  • Modified tests
  • Manually verified

@cttsai-stripe cttsai-stripe requested review from a team as code owners April 4, 2025 19:36
Copy link
Contributor Author

@cttsai-stripe cttsai-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to share the test rule for both DefaultEventReporterTest(unit test) and other analytics tests (android test). If I place the rule to somewhere they all can access like payments-core-testing, then AnalyticEventCallback can not be accessed by the rule. It seems that I can only write two rules for the test separately.

events.expectNoEvents()
events.ensureAllEventsConsumed()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure which one is better. Or should we use both?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the correct one.

Copy link
Contributor

github-actions bot commented Apr 4, 2025

Diffuse output:

OLD: identity-example-release-base.apk (signature: V1, V2)
NEW: identity-example-release-pr.apk (signature: V1, V2)

          │          compressed          │         uncompressed         
          ├───────────┬───────────┬──────┼───────────┬───────────┬──────
 APK      │ old       │ new       │ diff │ old       │ new       │ diff 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
      dex │     2 MiB │     2 MiB │  0 B │   4.1 MiB │   4.1 MiB │  0 B 
     arsc │     1 MiB │     1 MiB │  0 B │     1 MiB │     1 MiB │  0 B 
 manifest │   2.3 KiB │   2.3 KiB │  0 B │     8 KiB │     8 KiB │  0 B 
      res │ 302.9 KiB │ 302.9 KiB │  0 B │   457 KiB │   457 KiB │  0 B 
   native │   6.2 MiB │   6.2 MiB │  0 B │  15.8 MiB │  15.8 MiB │  0 B 
    asset │   7.3 KiB │   7.3 KiB │  0 B │   7.1 KiB │   7.1 KiB │  0 B 
    other │  95.1 KiB │  95.1 KiB │ +6 B │ 182.4 KiB │ 182.4 KiB │  0 B 
──────────┼───────────┼───────────┼──────┼───────────┼───────────┼──────
    total │   9.6 MiB │   9.6 MiB │ +6 B │  21.6 MiB │  21.6 MiB │  0 B 

 DEX     │ old   │ new   │ diff      
─────────┼───────┼───────┼───────────
   files │     1 │     1 │ 0         
 strings │ 20142 │ 20142 │ 0 (+0 -0) 
   types │  6235 │  6235 │ 0 (+0 -0) 
 classes │  5026 │  5026 │ 0 (+0 -0) 
 methods │ 30047 │ 30047 │ 0 (+0 -0) 
  fields │ 17385 │ 17385 │ 0 (+0 -0) 

 ARSC    │ old  │ new  │ diff 
─────────┼──────┼──────┼──────
 configs │  164 │  164 │  0   
 entries │ 3644 │ 3644 │  0
APK
   compressed    │   uncompressed   │                        
──────────┬──────┼───────────┬──────┤                        
 size     │ diff │ size      │ diff │ path                   
──────────┼──────┼───────────┼──────┼────────────────────────
 25.7 KiB │ +4 B │    64 KiB │  0 B │ ∆ META-INF/MANIFEST.MF 
   29 KiB │ +3 B │    64 KiB │  0 B │ ∆ META-INF/CERT.SF     
  1.2 KiB │ -1 B │   1.2 KiB │  0 B │ ∆ META-INF/CERT.RSA    
──────────┼──────┼───────────┼──────┼────────────────────────
 55.8 KiB │ +6 B │ 129.3 KiB │  0 B │ (total)

@@ -950,7 +933,7 @@ class DefaultEventReporterTest {
simulateSuccessfulSetup(linkMode = null, googlePayReady = false)
}

analyticEventCallbackProvider.set(null)
analyticEventCallbackRule.setCallback(null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the nulling it out happen automatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the default is to receive the event. The AnalyticEventCallbackRule will set the turbine as the default callback at the beginning of the tests and null them after finishing. This setting is reasonable to me because this reduce boilerplate code when testing all nine kinds of events.

analyticEventCall.add(event)
}

fun setCallback(callback: AnalyticEventCallback?) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for this? It seems kinda confusing that it can be set in two different ways?

Copy link
Contributor Author

@cttsai-stripe cttsai-stripe Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for setting non default callbacks, e.g. null callback or throwing errors. I think wrapping this as a function looks more like the callback builder in the production code. I can remove this setter and make the callback member variable public if that is better.

It seems kinda confusing that it can be set in two different ways?

I think there is only one setter exposed for this class?

@cttsai-stripe cttsai-stripe merged commit 410746d into master Apr 7, 2025
13 checks passed
@cttsai-stripe cttsai-stripe deleted the cttsai/analytic-event-callback-rule branch April 7, 2025 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants