How to terminate an api test that uses a repeating alarm?

7 views
Skip to first unread message

sq...@chromium.org

unread,
May 19, 2017, 1:42:34 PM5/19/17
to apps-dev
I have the following code that's running in an API test: https://pastebin.com/b7RU54ta

It initializes a repeating alarm and an alarm listener callback. The callback counts the number of alarms that have fired. On the 6th alarm, the callback will clear all alarms.

The test script runs without hitting any test failures, but it never terminates either. How do I get it to terminate?

Simon

Toni Barzic

unread,
May 19, 2017, 2:16:31 PM5/19/17
to sq...@chromium.org, apps-dev
You have to send a message to browser process indicating that the test has succeeded (check out API here: https://cs.chromium.org/chromium/src/extensions/common/api/test.json 

In this case, I think you want to use chrome.test.listenForever:
var done = chrome.test.listenForever(chrome.alarms.onAlarm, function(alarm) {
  // do stuf

  if (alarmCount >=5) {
    chrome.alarm.clearAllAlarms();
    done();   // Afaik, this should remove the listener to onAlarm and send message to browser
                  // process that the test succeed (provided there are no other pending test callbacks
                  // (e.g. chrome.test.callbackPass that hasn;t yet been run))
  }
});
Reply all
Reply to author
Forward
0 new messages