Skip to content
This repository has been archived by the owner on Sep 21, 2024. It is now read-only.

Commit

Permalink
Merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenge committed Apr 27, 2021
2 parents 1ad8514 + 2b3da63 commit 70bd091
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 21 deletions.
30 changes: 28 additions & 2 deletions AmbrosiaTest/AmbrosiaTest/JS_CodeGen_Neg_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Windows.Forms; // need this to handle threading issue on sleeps
using System.Configuration;
using System.IO;


namespace AmbrosiaTest
Expand Down Expand Up @@ -34,8 +35,33 @@ public void Initialize()


//************* Negative Tests *****************




// ** Shotgun approach of throwing a bunch of ts files against code gen and see if any fails beyond just saying it is not annotated
[TestMethod]
public void JS_CG_Neg_AmbrosiaSrcFiles_Test()
{
JS_Utilities JSUtils = new JS_Utilities();
Utilities MyUtils = new Utilities();

// get ambrosia-node source files
string AmbrosiaNodeDir = @"../../../../JSCodeGen/node_modules/ambrosia-node/src/";

// loop through all the Ambrosia JS src files and generate them
foreach (string currentSrcFile in Directory.GetFiles(AmbrosiaNodeDir, "*.ts"))
{

string fileName = Path.GetFileName(currentSrcFile);

string PrimaryErrorMessage = "Error: The input source file";
string SecondaryErrorMessage = " does not publish any entities (exported functions, static methods, type aliases and enums annotated with an @ambrosia JSDoc tag)";

// Generate the consumer and publisher files and verify output and the generated files to cmp files
JSUtils.Test_CodeGen_TSFile(fileName, true, PrimaryErrorMessage, SecondaryErrorMessage,true);
}
}


[TestMethod]
public void JS_CG_Neg_AmbrosiaTagNewLine()
{
Expand Down
73 changes: 57 additions & 16 deletions AmbrosiaTest/AmbrosiaTest/JS_Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,43 @@ public class JS_Utilities
public string CodeGenNoTypeScriptErrorsMessage = "Success: No TypeScript errors found in generated file ";

// Runs a TS file through the JS LB and verifies code gen works correctly
public void Test_CodeGen_TSFile(string TestFile, bool NegTest = false, string PrimaryErrorMessage = "", string SecondaryErrorMessage = "")
// Handles valid tests one way, Negative tests from a different directory and Source Files as negative tests
public void Test_CodeGen_TSFile(string TestFile, bool NegTest = false, string PrimaryErrorMessage = "", string SecondaryErrorMessage = "", bool UsingSrcTestFile = false)
{
try
{
// Test Name is just the file without the extension
string TestName = TestFile.Substring(0, TestFile.Length - 3);

Utilities MyUtils = new Utilities();
string ConSuccessString = CodeGenNoTypeScriptErrorsMessage + TestName+ "_GeneratedConsumerInterface.g.ts";
string PubSuccessString = CodeGenNoTypeScriptErrorsMessage + TestName+ "_GeneratedPublisherFramework.g.ts";
bool pass = true; // not actually used in this test but it is a generic utility fctn return

// Test Name is just the file without the extension
string TestName = TestFile.Substring(0, TestFile.Length - 3);

// Launch the client job process with these values
string testfileDir = @"../../AmbrosiaTest/JSCodeGen/JS_CodeGen_TestFiles/";
if (NegTest)
{
testfileDir = @"../../AmbrosiaTest/JSCodeGen/JS_CodeGen_TestFiles/NegativeTests/";
}
if (UsingSrcTestFile)
{
testfileDir = @"../../AmbrosiaTest/JSCodeGen/node_modules/ambrosia-node/src/";
TestName = "SRC_" + TestName;
}


string ConSuccessString = CodeGenNoTypeScriptErrorsMessage + TestName + "_GeneratedConsumerInterface.g.ts";
string PubSuccessString = CodeGenNoTypeScriptErrorsMessage + TestName + "_GeneratedPublisherFramework.g.ts";
bool pass = true; // not actually used in this test but it is a generic utility fctn return


string testappdir = ConfigurationManager.AppSettings["AmbrosiaJSCodeGenDirectory"];
string sourcefile = testfileDir+TestFile;
string sourcefile = testfileDir + TestFile;
string generatedfile = TestName + "_Generated";
string fileNameExe = "node.exe";
string argString = "out\\TestCodeGen.js sourceFile=" + sourcefile + " mergeType=None generatedFileName=" + generatedfile;
string testOutputLogFile = TestName + "_CodeGen_Out.log";


int processID = MyUtils.LaunchProcess(testappdir, fileNameExe, argString, false, testOutputLogFile);
if (processID <= 0)
{
Expand All @@ -54,14 +66,44 @@ public void Test_CodeGen_TSFile(string TestFile, bool NegTest = false, string Pr
// Verify things differently if it is a negative test
if (NegTest)
{
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, CodeGenFailMessage, 1, false, TestFile, true,false);
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, CodeGenFailMessage, 1, false, TestFile, true);

// Verify the log file only has the one error (one that is related to not being annotated)
if (UsingSrcTestFile)
{

string TestLogDir = ConfigurationManager.AppSettings["TestLogOutputDirectory"];
string outputFile = TestLogDir + "\\" + testOutputLogFile;

var total = 0;
using (StreamReader sr = new StreamReader(outputFile))
{

while (!sr.EndOfStream)
{
var counts = sr
.ReadLine()
.Split(' ')
.GroupBy(s => s)
.Select(g => new { Word = g.Key, Count = g.Count() });
var wc = counts.SingleOrDefault(c => c.Word == "Error:");
total += (wc == null) ? 0 : wc.Count;
}
}

// Look for "Error:" in the log file
if (total > 1)
{
Assert.Fail("<Test_CodeGen_TSFile> Failure! Found more than 1 error in output file:"+ testOutputLogFile);
}
}
}
else
{
// Wait to see if success comes shows up in log file for total and for consumer and publisher
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, CodeGenSuccessMessage, 1, false, TestFile, true,false);
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, ConSuccessString, 1, false, TestFile, true,false);
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, PubSuccessString, 1, false, TestFile, true,false);
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, CodeGenSuccessMessage, 1, false, TestFile, true);
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, ConSuccessString, 1, false, TestFile, true);
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, PubSuccessString, 1, false, TestFile, true);

// Verify the generated files with cmp files
string GenConsumerFile = TestName + "_GeneratedConsumerInterface.g.ts";
Expand All @@ -73,13 +115,14 @@ public void Test_CodeGen_TSFile(string TestFile, bool NegTest = false, string Pr
// Can use these to verify extra messages in the log file
if (PrimaryErrorMessage != "")
{
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, PrimaryErrorMessage, 1, false, TestFile, true,false);
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, PrimaryErrorMessage, 1, false, TestFile, true);
}
if (SecondaryErrorMessage != "")
{
pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, SecondaryErrorMessage, 1, false, TestFile, true,false);

pass = MyUtils.WaitForProcessToFinish(testOutputLogFile, SecondaryErrorMessage, 1, false, TestFile, true);
}


}
catch (Exception e)
{
Expand Down Expand Up @@ -179,8 +222,6 @@ public int StartJSTestApp(string testOutputLogFile)
return processID;
}



//** Clean up all the left overs from JS tests.
public void JS_TestCleanup()
{
Expand Down
9 changes: 6 additions & 3 deletions CONTRIBUTING/AMBROSIA_client_network_protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@ numbers involved: it simply has code/state for VCurrent and code/state for VNext
that the app can recover using VCurrent, but then proceed using VNext. When the LB receives `UpgradeTakeCheckpoint`
(or `UpgradeService` when doing an upgrade test) it switches over the state and code from VCurrent to VNext.
Note that the lack of version numbering from the LB's perspective is in contrast to the parameters supplied to
`Ambrosia.exe RegisterInstance` (see below) which are specific integer version numbers. These numbers refer to "the version
of the running instance", not "the version of the state/code". This loose relationship is by design to offer maximum
flexibility to the deployment configuration of the service.
`Ambrosia.exe RegisterInstance` (see below) which are specific integer version numbers. These numbers refer to "the migration
version of the instance", not "the version of the running state/code". This loose relationship is by design to offer maximum
flexibility to the deployment configuration of the service. For example, to perform a "downgrade", the downgraded code would be
included in the app as the VNext code, while the `upgradeVersion` number used in `RegisterInstance` to prepare for the
downgrade (see below) would still be increased. This illustrates how the term 'upgrade' is more accurately thought of as referring
to the _migration_ of code (and state).

Performing an upgrade of a standalone instance always involves stopping the app (or service), so it always involves downtime. The steps are:
* Stop the current instance.
Expand Down

0 comments on commit 70bd091

Please sign in to comment.