Skip to content
This repository has been archived by the owner before Nov 9, 2022. It is now read-only.

Test case, We provide notification when a listener dies and we recreate it, has a race condition on Android #719

Open
tompaana opened this issue Apr 27, 2016 · 1 comment
Assignees
Milestone

Comments

@tompaana
Copy link
Member

tompaana commented Apr 27, 2016

After adding logging to this test case (in thaliMobileNativeWrapper.js) I noticed a possible race condition: Function nonTCPAvaiHandler is called just before recreatedHandler leading to recreatedPort to be null.

Code:

...
      function recreatedHandler(record) {
        t.equal(record.peerIdentifier, peer.peerIdentifier, 'same ids');
        recreatedPort = record.portNumber;
      }
...
      function nonTCPAvaiHandler(record) {
        if (record.peerIdentifier !== peer.peerIdentifier) {
          logger.debug('Peer identifiers do not match: '
            + record.peerIdentifier + ' !== ' + peer.peerIdentifier);
          return;
        }
        if (!recreatedPort ||
          recreatedPort && record.portNumber !== recreatedPort) {
          logger.debug('No recreated port or port numbers do not match: '
            + record.portNumber + ' !== ' + recreatedPort);
          return;
        }
        testUtils.get('127.0.0.1', record.portNumber, testPath, pskIdentity,
                      pskKey)
          .then(function (responseBody) {
            t.equal(responseBody, testData, 'matching bodies');
            exit();
          })
          .catch(function (err) {
            t.fail(err);
            exit();
          });
      }
...

Log:

04-27 04:06:41.387 27171-27321/com.test.thalitest I/jxcore-log: DEBUG createPeerListener: Recreating listener
04-27 04:06:41.394 27171-27321/com.test.thalitest I/jxcore-log: DEBUG createPeerListener: createPeerListener creating new server
04-27 04:06:41.400 27171-27321/com.test.thalitest I/jxcore-log: DEBUG createPeerListener: pleaseConnect= false
04-27 04:06:41.406 27171-27321/com.test.thalitest I/jxcore-log: DEBUG testThaliMobileNativeWrapper: No recreated port or port numbers do not match: 48750 !== null
04-27 04:06:41.408 27171-27321/com.test.thalitest I/jxcore-log: ok 311 same ids
@tompaana
Copy link
Member Author

tompaana commented Apr 27, 2016

After commenting out this check

        if (!recreatedPort ||
          recreatedPort && record.portNumber !== recreatedPort) {
          logger.debug('No recreated port or port numbers do not match: '
            + record.portNumber + ' !== ' + recreatedPort);
          return;
        }

...the test passes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants