Skip to content

Commit

Permalink
Begin removing sleeps from mazerunner scenarios (#478)
Browse files Browse the repository at this point in the history
Begin removing sleeps from mazerunner scenarios
  • Loading branch information
fractalwrench committed May 17, 2019
2 parents 2674dfd + 69797ed commit 0ebdad0
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 37 deletions.
1 change: 0 additions & 1 deletion features/error_context.feature
Expand Up @@ -2,7 +2,6 @@ Feature: Reporting Error Context

Scenario: Context automatically set as most recent Activity name
When I run "AutoContextScenario"
And I wait for 3 seconds
Then I should receive a request
And the request is a valid for the error reporting API
And the "Bugsnag-API-Key" header equals "a35a2a72bd230ac0aa0f52715bbdc6aa"
Expand Down
Expand Up @@ -22,7 +22,6 @@ internal class AsyncErrorConnectivityScenario(config: Configuration,
writeErrorToStore(Bugsnag.getClient())
flushErrorStoreAsync(Bugsnag.getClient())
flushErrorStoreOnLaunch(Bugsnag.getClient())
Thread.sleep(50)
}

}
Expand Up @@ -20,7 +20,6 @@ internal class AsyncErrorDoubleFlushScenario(config: Configuration,
writeErrorToStore(Bugsnag.getClient())
flushErrorStoreAsync(Bugsnag.getClient())
flushErrorStoreAsync(Bugsnag.getClient())
Thread.sleep(50)
}

}
Expand Up @@ -21,7 +21,6 @@ internal class AsyncErrorLaunchScenario(config: Configuration,
writeErrorToStore(Bugsnag.getClient())
flushErrorStoreOnLaunch(Bugsnag.getClient())
flushErrorStoreAsync(Bugsnag.getClient())
Thread.sleep(50)
}

}
Expand Up @@ -3,6 +3,8 @@ package com.bugsnag.android.mazerunner.scenarios
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle

import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import com.bugsnag.android.mazerunner.SecondActivity
Expand All @@ -18,12 +20,11 @@ internal class AutoContextScenario(config: Configuration,

override fun run() {
super.run()
registerActivityLifecycleCallbacks()
context.startActivity(Intent(context, SecondActivity::class.java))

val a = context as Activity
a.window.decorView.postDelayed({
Bugsnag.notify(generateException())
}, 2000)
}

override fun onActivityStarted(activity: Activity) {
Bugsnag.notify(generateException())
}
}
Expand Up @@ -2,14 +2,14 @@

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.bugsnag.android.Configuration;
import com.bugsnag.android.mazerunner.SecondActivity;

import android.content.Intent;
import android.support.annotation.NonNull;

import com.bugsnag.android.mazerunner.SecondActivity;

public class CXXAutoContextScenario extends Scenario {

static {
Expand All @@ -29,16 +29,12 @@ public CXXAutoContextScenario(@NonNull Configuration config, @NonNull Context co
public void run() {
super.run();
Context context = getContext();
registerActivityLifecycleCallbacks();
context.startActivity(new Intent(context, SecondActivity.class));
}

if (context instanceof Activity) {
Activity activity = (Activity)context;
activity.getWindow().getDecorView().postDelayed(new Runnable() {
@Override
public void run() {
activate();
}
}, 2000);
}
@Override
public void onActivityStarted(Activity activity) {
activate();
}
}
Expand Up @@ -33,11 +33,6 @@ public void run() {
return;
}
Bugsnag.leaveBreadcrumb("Reverse thrusters");
handler.postDelayed(new Runnable() {
@Override
public void run() {
activate();
}
}, 1000);
activate();
}
}
@@ -1,6 +1,9 @@
package com.bugsnag.android.mazerunner.scenarios

import android.app.Activity
import android.content.Context
import android.os.Bundle

import com.bugsnag.android.Bugsnag
import com.bugsnag.android.Configuration
import java.lang.Thread
Expand All @@ -19,14 +22,11 @@ internal class InForegroundScenario(config: Configuration,

override fun run() {
super.run()
registerActivityLifecycleCallbacks()
}

val thread = HandlerThread("HandlerThread")
thread.start()
Handler(thread.looper).post {
Thread.sleep(5000)
Bugsnag.notify(generateException())
}

override fun onActivityStopped(activity: Activity) {
Bugsnag.notify(generateException())
}

}
@@ -1,10 +1,16 @@
package com.bugsnag.android.mazerunner.scenarios

import android.app.Activity
import android.app.Application
import android.os.Bundle
import android.content.Context

import com.bugsnag.android.*

abstract internal class Scenario(protected val config: Configuration,
protected val context: Context) {
abstract internal class Scenario(
protected val config: Configuration,
protected val context: Context
): Application.ActivityLifecycleCallbacks {

var eventMetaData: String? = null

Expand Down Expand Up @@ -72,4 +78,19 @@ abstract internal class Scenario(protected val config: Configuration,
*/
protected fun generateException(): Throwable = RuntimeException(javaClass.simpleName)


/* Activity lifecycle callback overrides */

protected fun registerActivityLifecycleCallbacks() {
(context.applicationContext as Application).registerActivityLifecycleCallbacks(this)
}

override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {}
override fun onActivityStarted(activity: Activity) {}
override fun onActivityResumed(activity: Activity) {}
override fun onActivityPaused(activity: Activity) {}
override fun onActivityStopped(activity: Activity) {}
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) {}
override fun onActivityDestroyed(activity: Activity) {}

}
2 changes: 1 addition & 1 deletion features/in_foreground.feature
@@ -1,7 +1,7 @@
Feature: In foreground field populates correctly

Scenario: Test handled exception after delay
When I run "InForegroundScenario"
When I run "HandledExceptionScenario"
Then I should receive a request
And the request is a valid for the error reporting API
And the event "app.inForeground" is true
Expand Down

0 comments on commit 0ebdad0

Please sign in to comment.