You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2018/09/05 22:25:20 UTC

[cordova-coho] branch master updated: GH-195: Ensure synchronous operation

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-coho.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ae50f2  GH-195: Ensure synchronous operation
2ae50f2 is described below

commit 2ae50f2200c352f2a69b731a79f10562c5c41bc6
Author: Oliver <ol...@gmail.com>
AuthorDate: Wed Sep 5 21:59:36 2018 +0200

    GH-195: Ensure synchronous operation
    
    Performing the read asynchronously introduces a race condition that can
    cause the changes to not have been made yet
    when they are checked by git.
    
    This issue introduces random nightly build failures.
    
    Fixes #195
---
 spec/versionutil.spec.js | 22 ++++++++++++----------
 src/versionutil.js       | 22 +++++++++-------------
 2 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/spec/versionutil.spec.js b/spec/versionutil.spec.js
index 7c1c04d..c84d342 100644
--- a/spec/versionutil.spec.js
+++ b/spec/versionutil.spec.js
@@ -22,6 +22,7 @@ var jasmine_co = require('jasmine-co').install();
 var fs = require('fs');
 var path = require('path');
 var shell = require('shelljs');
+var xml2js = require('xml2js');
 var repoutil = require('../src/repoutil');
 var executil = require('../src/executil');
 var gitutil = require('../src/gitutil');
@@ -58,7 +59,8 @@ describe("Correct version is passed to gradle.build", function () {
 	var shellSpy;
 	beforeEach(function* () {
 		spyOn(fs, 'writeFileSync').and.returnValue(true);
-		spyOn(fs, 'readFile').and.returnValue(true);
+		spyOn(fs, 'readFileSync').and.returnValue("{}");
+		spyOn(xml2js, 'parseString').and.returnValue(true);
 		spyOn(fs,'existsSync').and.returnValue(true);
 		shellSpy = spyOn(shell,'sed').and.returnValue(true);
 		spyOn(apputil, 'print').and.returnValue(true);
@@ -73,7 +75,7 @@ describe("Correct version is passed to gradle.build", function () {
 
 	afterEach(function () {
 		fs.writeFileSync.calls.reset();
-		fs.readFile.calls.reset();
+		fs.readFileSync.calls.reset();
 		fs.existsSync.calls.reset();
 		shell.sed.calls.reset();
 		apputil.print.calls.reset();
@@ -85,9 +87,9 @@ describe("Correct version is passed to gradle.build", function () {
 	it("Test#001 : checks that the correct android version is passed in", function* () {
 		var androidVersion = yield versionutil.updateRepoVersion(androidRepo, "6.4.0-dev");
 		// Check call count
-		expect(fs.writeFileSync.calls.count()).toEqual(1);
+		expect(fs.writeFileSync.calls.count()).toEqual(2);
 		expect(fs.existsSync.calls.count()).toEqual(4);
-		expect(fs.readFile.calls.count()).toEqual(3);
+		expect(fs.readFileSync.calls.count()).toEqual(3);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
 		expect(gitutil.pendingChangesExist.calls.count()).toEqual(4);
@@ -105,10 +107,10 @@ describe("Correct version is passed to gradle.build", function () {
 	it("Test#002 : checks that the correct ios version is passed in", function* () {
 		var iosVersion = yield versionutil.updateRepoVersion(iosRepo, "4.2.0-dev");
 		// Check call count
-		expect(fs.writeFileSync.calls.count()).toEqual(1);
+		expect(fs.writeFileSync.calls.count()).toEqual(2);
 		expect(fs.existsSync.calls.count()).toEqual(4);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
-		expect(fs.readFile.calls.count()).toEqual(3);
+		expect(fs.readFileSync.calls.count()).toEqual(3);
 		expect(gitutil.pendingChangesExist.calls.count()).toEqual(4);
 		expect(shell.sed.calls.count()).toEqual(1);
 		expect(apputil.print.calls.count()).toEqual(0);
@@ -120,11 +122,11 @@ describe("Correct version is passed to gradle.build", function () {
 	it("Test#003 : checks that the correct windows version is passed in", function* () {
 		var windowsVersion = yield versionutil.updateRepoVersion(windowsRepo, "4.5.0-dev");
 		// Check call count
-		expect(fs.writeFileSync.calls.count()).toEqual(1);
+		expect(fs.writeFileSync.calls.count()).toEqual(2);
 		expect(fs.existsSync.calls.count()).toEqual(5);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
 		expect(gitutil.pendingChangesExist.calls.count()).toEqual(4);
-		expect(fs.readFile.calls.count()).toEqual(3);
+		expect(fs.readFileSync.calls.count()).toEqual(3);
 		expect(shell.sed.calls.count()).toEqual(1);
 		expect(apputil.print.calls.count()).toEqual(0);
 		expect(executil.execHelper.calls.count()).toEqual(1);
@@ -135,11 +137,11 @@ describe("Correct version is passed to gradle.build", function () {
 	it("Test#004 : check that the correct browser version is passed in", function* () {
 		var browserVersion = yield versionutil.updateRepoVersion(browserRepo, "4.1.0-dev");
 		//Check call count
-		expect(fs.writeFileSync.calls.count()).toEqual(1);
+		expect(fs.writeFileSync.calls.count()).toEqual(2);
 		expect(fs.existsSync.calls.count()).toEqual(5);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
 		expect(gitutil.pendingChangesExist.calls.count()).toEqual(4);
-		expect(fs.readFile.calls.count()).toEqual(3);
+		expect(fs.readFileSync.calls.count()).toEqual(3);
 		expect(shell.sed.calls.count()).toEqual(1);
 		expect(apputil.print.calls.count()).toEqual(0);
 		expect(executil.execHelper.calls.count()).toEqual(1);
diff --git a/src/versionutil.js b/src/versionutil.js
index 7c19099..9dedbcd 100644
--- a/src/versionutil.js
+++ b/src/versionutil.js
@@ -131,13 +131,11 @@ exports.updateRepoVersion = function * updateRepoVersion (repo, version, opts) {
     // Update the package.json VERSION.
     var packageFilePaths = repo.packageFilePaths || ['package.json'];
     if (fs.existsSync(packageFilePaths[0])) {
-        fs.readFile(packageFilePaths[0], {encoding: 'utf-8'}, function (err, data) {
-            if (err) throw err;
-            var packageJSON = JSON.parse(data);
-            packageJSON.version = version;
-            // use 2 spaces indent similar to npm
-            fs.writeFileSync(packageFilePaths[0], JSON.stringify(packageJSON, null, 2) + '\n');
-        });
+        var data = fs.readFileSync(packageFilePaths[0], {encoding: 'utf-8'});
+        var packageJSON = JSON.parse(data);
+        packageJSON.version = version;
+        // use 2 spaces indent similar to npm
+        fs.writeFileSync(packageFilePaths[0], JSON.stringify(packageJSON, null, 2) + '\n');
         if (!(yield gitutil.pendingChangesExist())) {
             apputil.print('package.json file was already up-to-date.');
         }
@@ -151,13 +149,11 @@ exports.updateRepoVersion = function * updateRepoVersion (repo, version, opts) {
         var xmlFilePaths = repo.xmlFilePaths || ['plugin.xml', 'tests/plugin.xml'];
         xmlFilePaths.forEach(function (xmlFile) {
             if (fs.existsSync(xmlFile)) {
-                fs.readFile(xmlFile, {encoding: 'utf-8'}, function (err, data) {
+                var data = fs.readFileSync(xmlFile, {encoding: 'utf-8'});
+                xml2js.parseString(data, {async: false}, function (err, xml) {
                     if (err) throw err;
-                    xml2js.parseString(data, function (err, xml) {
-                        if (err) throw err;
-                        var prev_version = xml.plugin['$'].version;
-                        shelljs.sed('-i', new RegExp('version="' + prev_version + '"', 'i'), 'version="' + version + '"', xmlFile);
-                    });
+                    var prev_version = xml.plugin['$'].version;
+                    shelljs.sed('-i', new RegExp('version="' + prev_version + '"', 'i'), 'version="' + version + '"', xmlFile);
                 });
             } else {
                 console.warn('No ' + xmlFile + ' file exists in repo ' + repo.repoName);


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org