Got JS_UpdateJSConfigFile working

This commit is contained in:
Darren Gehring 2021-08-16 15:29:21 -07:00
Родитель d889ec8fe4
Коммит 4d8545b1d4
11 изменённых файлов: 172 добавлений и 53 удалений

3
.gitignore поставляемый
Просмотреть файл

@ -268,3 +268,6 @@ CodeGenDependencies
/BuildAmbrosiaAfterNugetChange.ps1
/AmbrosiaBak
/AmbrosiaTest/JSCodeGen/out
/AmbrosiaTest/JSTest/PTI
/AmbrosiaTest/JSTest/out
/AmbrosiaTest/JSTest/ambrosiaConfig.json.old

Просмотреть файл

@ -69,6 +69,7 @@
<Reference Include="System.Windows.Forms">
<Private>True</Private>
</Reference>
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ActiveActive_Test.cs" />
@ -80,6 +81,7 @@
<Compile Include="InProc_TCP_Test.cs" />
<Compile Include="JS_CodeGen_Neg_Tests.cs" />
<Compile Include="JS_CodeGen_Tests.cs" />
<Compile Include="JS_PTI_BasicUnitTests.cs" />
<Compile Include="MTF_Test.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="JS_Tests.cs" />
@ -112,19 +114,22 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeCoverage">
<Version>16.6.1</Version>
<Version>16.11.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk">
<Version>16.6.1</Version>
<Version>16.11.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.TestPlatform.TestHost">
<Version>16.6.1</Version>
<Version>16.11.0</Version>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter">
<Version>2.1.2</Version>
<Version>2.2.5</Version>
</PackageReference>
<PackageReference Include="MSTest.TestFramework">
<Version>2.1.2</Version>
<Version>2.2.5</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -20,7 +20,7 @@ namespace AmbrosiaTest
JS_Utilities JSUtils = new JS_Utilities();
MyUtils.TestInitialize();
JSUtils.BuildJSTestApp();
//JSUtils.BuildJSTestApp(); -- maybe don't do this - not needed to build every time ... could assume it is built as well
}
//************* Init Code *****************
@ -30,20 +30,29 @@ namespace AmbrosiaTest
{
// Kill all exes associated with tests
JS_Utilities JSUtils = new JS_Utilities();
JSUtils.JS_PTI_TestCleanup();
JSUtils.JS_TestCleanup();
}
[TestMethod]
public void JS_PTI_BasicEndToEnd_Test()
public void JS_PTI_BasicBiDiEndToEnd_Test()
{
// ** Probably set in Init
// ** Set AUtoregister = true, Log dirs, binary directory
Utilities MyUtils = new Utilities();
JS_Utilities JSUtils = new JS_Utilities();
string testName = "jsptiendtoendtest";
string testName = "jsptibidiendtoendtest";
string logOutputFileName_TestApp = testName + "_TestApp.log";
JSUtils.JS_UpdateJSConfigFile(JSUtils.JSConfig_instanceName, testName);
JSUtils.StartJSTestApp(JSUtils.JSPTI_CombinedInstanceRole, logOutputFileName_TestApp);
bool pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, "Bytes received: 256", 5, false, testName, true); // number of bytes processed
pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, "SUCCESS: The expected number of bytes (256) have been received", 5, false, testName, true); // number of bytes processed
pass = MyUtils.WaitForProcessToFinish(logOutputFileName_TestApp, "SUCCESS: The expected number of echoed bytes (256) have been received", 5, false, testName, true); // number of bytes processed
}
}
}

Просмотреть файл

@ -7,6 +7,8 @@ using System.Threading;
using System.Windows.Forms; // need this to handle threading issue on sleeps
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace AmbrosiaTest
{
@ -18,6 +20,25 @@ namespace AmbrosiaTest
public string CodeGenFailMessage = "Code file generation FAILED: 0 of 2 files generated";
public string CodeGenNoTypeScriptErrorsMessage = "Success: No TypeScript errors found in generated file ";
public string JSPTI_CombinedInstanceRole = "Combined";
public string JSPTI_ClientInstanceRole = "Client";
public string JSPTI_ServerInstanceRole = "Server";
//** Config Settings in ambrosiaConfig.json
public string JSConfig_autoRegister = "autoRegister";
public string JSConfig_instanceName = "instanceName";
public string JSConfig_icCraPort = "icCraPort";
public string JSConfig_icReceivePort = "icReceivePort";
public string JSConfig_icLogFolder = "icLogFolder";
public string JSConfig_icBinFolder = "icBinFolder";
public string JSConfig_useNetCore = "useNetCore";
public string JSConfig_logTriggerSizeinMB = "logTriggerSizeInMB";
public string JSConfig_debugStartCheckpoint = "debugStartCheckpoint";
public string JSConfig_debugTestUpgrade = "debugTestUpgrade";
public string JSConfig_appVersion = "appVersion";
public string JSConfig_upgradeVersion = "upgradeVersion";
// Runs a TS file through the JS LB and verifies code gen works correctly
// 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)
@ -204,15 +225,18 @@ namespace AmbrosiaTest
// Start Javascript Test App
public int StartJSTestApp(string testOutputLogFile)
public int StartJSTestApp(string instanceRole, string testOutputLogFile)
{
//node.\out\main.js - ir = Combined - n = 2 - bpr = 128 - mms = 32 - bsc = 32 - bd - nhc
// instanceRole role == Client, Server or Combined
Utilities MyUtils = new Utilities();
// Launch the client job process with these values
string workingDir = ConfigurationManager.AppSettings["AmbrosiaJSTestDirectory"];
string workingDir = ConfigurationManager.AppSettings["AmbrosiaJSTestDirectory"]+"\\PTI\\App";
string fileNameExe = "node.exe";
string argString = "out\\TestApp.js";
string argString = "out\\main.js -ir="+instanceRole+" -n=2 -bpr=128 -mms=32 -bsc=32 -bd -nhc -efb=256 -eeb=256";
int processID = MyUtils.LaunchProcess(workingDir, fileNameExe, argString, false, testOutputLogFile);
if (processID <= 0)
@ -222,12 +246,59 @@ namespace AmbrosiaTest
}
// Give it a few seconds to start
Thread.Sleep(6000);
Thread.Sleep(5000);
Application.DoEvents(); // if don't do this ... system sees thread as blocked thread and throws message.
return processID;
}
//** Restores the JS Config file for the test app from the golden config file
//** Probably called in init
public void JS_RestoreJSConfigFile()
{
Utilities MyUtils = new Utilities();
//*#*#* TO DO
//*#*#* Finish this
//*#*#* Update Init of JS to add this
//*#*# Update Init to set Auto Register
// Copy from JSTest\ambrosiaConfigGOLD.json to PTI\App\ambrosiaConfig.json
}
//** Sets a JS Config File (ambrosiaConfig.json) setting
public void JS_UpdateJSConfigFile(string key, string newValue)
{
try
{
string data = string.Empty;
string basePath = ConfigurationManager.AppSettings["AmbrosiaJSTestDirectory"] + "\\PTI\\App";
string ambrosiaConfigfileName = "ambrosiaConfig.json";
string ConfigFile = basePath+"\\"+ambrosiaConfigfileName;
//** Read JSON config file
data = File.ReadAllText(ConfigFile);
var jo1 = JObject.Parse(data);
var tz = jo1[key];
var currentValue = ((Newtonsoft.Json.Linq.JValue)tz).Value;
var typeOfCurrentValue = currentValue.GetType();
((Newtonsoft.Json.Linq.JValue)tz).Value = Convert.ChangeType(newValue, typeOfCurrentValue);
//** Write the key \ value
string dataObj = JsonConvert.SerializeObject(jo1, Formatting.Indented);
Directory.CreateDirectory(basePath);
File.WriteAllText(Path.Combine(basePath, ambrosiaConfigfileName), dataObj);
}
catch (Exception e)
{
Assert.Fail("<JS_UpdateJSConfigFile> Failure! " + e.Message);
}
}
//** Clean up all the left overs from JS tests.
public void JS_TestCleanup()
{
@ -243,6 +314,10 @@ namespace AmbrosiaTest
MyUtils.StopAllAmbrosiaProcesses();
Thread.Sleep(2000);
// Clean up Azure - this is called after each test so put all test names in for azure tables
MyUtils.CleanupAzureTables("jsptibidiendtoendtest");
Thread.Sleep(2000);
}

Просмотреть файл

@ -105,10 +105,6 @@
<assemblyIdentity name="System.Text.Encoding.CodePages" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Xml.ReaderWriter" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />

Просмотреть файл

@ -31,6 +31,7 @@
</PropertyGroup>
<ItemGroup>
<Content Include="ambrosiaConfig.json" />
<Content Include="ambrosiaConfigGOLD.json" />
<Content Include="package.json" />
</ItemGroup>
<ItemGroup>

Просмотреть файл

@ -15,7 +15,7 @@
},
"instanceName": {
"type": "string",
"description": "The name this Ambrosia Immortal instance will be referred to by all instances (including itself).",
"description": "The name this Ambrosia Immortal instance will be referred to by all instances (including itself).\nSee https://github.com/microsoft/AMBROSIA#ambrosia-concepts",
"default": "myInstance"
},
"icCraPort": {
@ -37,7 +37,7 @@
"icLogStorageType" : {
"type": "string",
"enum": [ "Files", "Blobs" ],
"description": "The storage type that the Immortal Coordinator (IC) logs will be persisted in. Defaults to \"Files\".",
"description": "The storage type that the Immortal Coordinator (IC) logs will be persisted in. When set to \"Blobs\", icLogFolder can be an empty string. Defaults to \"Files\".",
"default": "Files"
},
"icBinFolder": {
@ -128,9 +128,9 @@
},
"outputLoggingLevel": {
"type": "string",
"enum": [ "Minimal", "Normal", "Verbose" ],
"default": "Normal",
"description": "The level of detail to include in the language-binding output log. Defaults to \"Normal\"."
"enum": [ "Minimal", "Verbose", "Debug" ],
"default": "Minimal",
"description": "The level of detail to include in the language-binding output log. Defaults to \"Minimal\".\nWARNING: Any value other than \"Minimal\" will significantly degrade performance."
},
"outputLogDestination": {
"type": "string",

Просмотреть файл

@ -1,27 +1,28 @@
{
"$schema": "./ambrosiaConfig-schema.json",
"autoRegister": true,
"instanceName": "server",
"icCraPort": 2500,
"icReceivePort": 2000,
"icSendPort": 2001,
"icLogFolder": "D:/AmbrosiaTest/logs/",
"icBinFolder": "D:/Ambrosia/AmbrosiaTest/AmbrosiaTest/bin/x64/Release",
"useNetCore": false,
"logTriggerSizeInMB": 1024,
"debugStartCheckpoint": 0,
"debugTestUpgrade": false,
"appVersion": 0,
"upgradeVersion": 0,
"activeCode": "VCurrent",
"lbOptions": {
"deleteLogs": true,
"deleteRemoteCRAConnections": false,
"outputLogDestination": "ConsoleAndFile",
"outputLogFolder": "./outputLogs",
"outputLoggingLevel": "Normal",
"allowDisplayOfRpcParams": true,
"allowPostMethodTimeouts": true,
"enableTypeScriptStackTraces": true
}
"$schema": "./ambrosiaConfig-schema.json",
"autoRegister": false,
"instanceName": "server",
"icCraPort": 2500,
"icReceivePort": 2000,
"icSendPort": 2001,
"icLogFolder": "C:/logs/",
"icBinFolder": "C:/src/Git/PostSledgehammer/AMBROSIA/ImmortalCoordinator/bin/x64/Release;C:/src/Git/PostSledgehammer/AMBROSIA/Ambrosia/Ambrosia/bin/x64/Release",
"useNetCore": false,
"logTriggerSizeInMB": 1024,
"debugStartCheckpoint": 0,
"debugTestUpgrade": false,
"appVersion": 0,
"upgradeVersion": 0,
"activeCode": "VCurrent",
"lbOptions":
{
"deleteLogs": true,
"deleteRemoteCRAConnections": false,
"outputLogDestination": "ConsoleAndFile",
"outputLogFolder": "./outputLogs",
"outputLoggingLevel": "Verbose",
"allowDisplayOfRpcParams": true,
"allowPostMethodTimeouts": true,
"enableTypeScriptStackTraces": true
}
}

Просмотреть файл

@ -0,0 +1,29 @@
{
"$schema": "./ambrosiaConfig-schema.json",
"autoRegister": true,
"instanceName": "INSTANCE_NAME",
"icCraPort": 2520,
"icReceivePort": 2020,
"icSendPort": 2021,
"icLogFolder": "LOG_FOLDER",
"icBinFolder": "BIN_FOLDER",
"useNetCore": false,
"logTriggerSizeInMB": 256,
"debugStartCheckpoint": 0,
"debugTestUpgrade": false,
"appVersion": 0,
"upgradeVersion": 0,
"activeCode": "VCurrent",
"lbOptions":
{
"deleteLogs": true,
"deleteRemoteCRAConnections": false,
"outputLogDestination": "ConsoleAndFile",
"outputLogFolder": "./outputLogs",
"outputLoggingLevel": "Minimal",
"allowDisplayOfRpcParams": true,
"allowPostMethodTimeouts": true,
"enableTypeScriptStackTraces": true,
"messageBytePoolSizeInMB": 2
}
}

10
AmbrosiaTest/JSTest/package-lock.json сгенерированный
Просмотреть файл

@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"@types/node": {
"version": "16.4.12",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.4.12.tgz",
"integrity": "sha512-zxrTNFl9Z8boMJXs6ieqZP0wAhvkdzmHSxTlJabM16cf5G9xBc1uPRH5Bbv2omEDDiM8MzTfqTJXBf0Ba4xFWA=="
"version": "16.6.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.6.1.tgz",
"integrity": "sha512-Sr7BhXEAer9xyGuCN3Ek9eg9xPviCF2gfu9kTfuU2HkTVAMYSDeX40fvpmo72n5nansg3nsBjuQBrsS28r+NUw=="
},
"ajv": {
"version": "6.12.6",
@ -21,8 +21,8 @@
}
},
"ambrosia-node": {
"version": "file:ambrosia-node-0.0.82.tgz",
"integrity": "sha512-DOXDIIMWp2Ro/AUnnGJuYxL6oKukGchaGZdE9KWOJU6/SdOSH9jI2TcfS6c5u7p8Jn9TVP9yKpzNuXd7171i8g==",
"version": "file:ambrosia-node-0.0.83.tgz",
"integrity": "sha512-mSjKtZWhPS+6DB6OAe6cz7HSbCFGswKupAACN4zSwuRZnqDrOrGsO8fmElBZh5qaMXmK082VDtvjcYAovQVCqA==",
"requires": {
"@types/node": "^16.4.12",
"azure-storage": "^2.10.4",

Просмотреть файл

@ -7,7 +7,7 @@
"name": ""
},
"dependencies": {
"ambrosia-node": "file:ambrosia-node-0.0.82.tgz",
"ambrosia-node": "file:ambrosia-node-0.0.83.tgz",
"typescript": "^4.3.5"
}
}