Adds debug logging for containerlog-searching operations

This commit is contained in:
benbierens 2023-06-01 15:20:21 +02:00
parent 99c9b25487
commit 37f7f5293f
No known key found for this signature in database
GPG Key ID: FE44815D96D0A1AA
3 changed files with 23 additions and 2 deletions

View File

@ -32,6 +32,11 @@ namespace DistTestCore
lifecycle.Log.Log($"{GetClassName()} {msg}"); lifecycle.Log.Log($"{GetClassName()} {msg}");
} }
protected void Debug(string msg)
{
lifecycle.Log.Debug($"{GetClassName()} {msg}", 1);
}
private string GetClassName() private string GetClassName()
{ {
return $"({GetType().Name})"; return $"({GetType().Name})";

View File

@ -24,7 +24,7 @@ namespace DistTestCore.Marketplace
WaitUntil(() => WaitUntil(() =>
{ {
var logHandler = new ContractsReadyLogHandler(); var logHandler = new ContractsReadyLogHandler(Debug);
workflow.DownloadContainerLog(container, logHandler); workflow.DownloadContainerLog(container, logHandler);
return logHandler.Found; return logHandler.Found;
}); });
@ -76,12 +76,20 @@ namespace DistTestCore.Marketplace
private const string RequiredCompiledString = "Solidity files successfully"; private const string RequiredCompiledString = "Solidity files successfully";
// When script is done, it prints the ready-string. // When script is done, it prints the ready-string.
private const string ReadyString = "Done! Sleeping indefinitely..."; private const string ReadyString = "Done! Sleeping indefinitely...";
private readonly Action<string> debug;
public ContractsReadyLogHandler(Action<string> debug)
{
this.debug = debug;
debug($"Looking for '{RequiredCompiledString}' and '{ReadyString}' in container logs...");
}
public bool SeenCompileString { get; private set; } public bool SeenCompileString { get; private set; }
public bool Found { get; private set; } public bool Found { get; private set; }
protected override void ProcessLine(string line) protected override void ProcessLine(string line)
{ {
debug(line);
if (line.Contains(RequiredCompiledString)) SeenCompileString = true; if (line.Contains(RequiredCompiledString)) SeenCompileString = true;
if (SeenCompileString && line.Contains(ReadyString)) Found = true; if (SeenCompileString && line.Contains(ReadyString)) Found = true;

View File

@ -79,7 +79,7 @@ namespace DistTestCore.Marketplace
private string FetchPubKey() private string FetchPubKey()
{ {
var enodeFinder = new PubKeyFinder(); var enodeFinder = new PubKeyFinder(s => log.Debug(s));
workflow.DownloadContainerLog(container, enodeFinder); workflow.DownloadContainerLog(container, enodeFinder);
return enodeFinder.GetPubKey(); return enodeFinder.GetPubKey();
} }
@ -103,8 +103,15 @@ namespace DistTestCore.Marketplace
{ {
private const string openTag = "self=enode://"; private const string openTag = "self=enode://";
private const string openTagQuote = "self=\"enode://"; private const string openTagQuote = "self=\"enode://";
private readonly Action<string> debug;
private string pubKey = string.Empty; private string pubKey = string.Empty;
public PubKeyFinder(Action<string> debug)
{
this.debug = debug;
debug($"Looking for '{openTag}' in container logs...");
}
public string GetPubKey() public string GetPubKey()
{ {
if (string.IsNullOrEmpty(pubKey)) throw new Exception("Not found yet exception."); if (string.IsNullOrEmpty(pubKey)) throw new Exception("Not found yet exception.");
@ -113,6 +120,7 @@ namespace DistTestCore.Marketplace
protected override void ProcessLine(string line) protected override void ProcessLine(string line)
{ {
debug(line);
if (line.Contains(openTag)) if (line.Contains(openTag))
{ {
ExtractPubKey(openTag, line); ExtractPubKey(openTag, line);