-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Replace output consumer with `IContainer.GetLogsAsync(DateTime,…
… DateTime, bool, CancellationToken)` (#793)
- Loading branch information
1 parent
eaa6068
commit d3ae00f
Showing
21 changed files
with
138 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 10 additions & 15 deletions
25
src/Testcontainers/Configurations/WaitStrategies/UntilMessageIsLogged.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
namespace DotNet.Testcontainers.Configurations | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
using System.Threading.Tasks; | ||
using DotNet.Testcontainers.Containers; | ||
|
||
internal class UntilMessageIsLogged : IWaitUntil | ||
{ | ||
private readonly string message; | ||
private readonly Regex pattern; | ||
|
||
private readonly Stream stream; | ||
public UntilMessageIsLogged(string pattern) | ||
: this(new Regex(pattern, RegexOptions.None, TimeSpan.FromSeconds(5))) | ||
{ | ||
} | ||
|
||
public UntilMessageIsLogged(Stream stream, string message) | ||
public UntilMessageIsLogged(Regex pattern) | ||
{ | ||
this.stream = stream; | ||
this.message = message; | ||
this.pattern = pattern; | ||
} | ||
|
||
public async Task<bool> UntilAsync(IContainer container) | ||
{ | ||
this.stream.Seek(0, SeekOrigin.Begin); | ||
|
||
using (var streamReader = new StreamReader(this.stream, Encoding.UTF8, false, 4096, true)) | ||
{ | ||
var output = await streamReader.ReadToEndAsync() | ||
.ConfigureAwait(false); | ||
var (stdout, stderr) = await container.GetLogsAsync(timestampsEnabled: false) | ||
.ConfigureAwait(false); | ||
|
||
return Regex.IsMatch(output, this.message, RegexOptions.None, TimeSpan.FromSeconds(1)); | ||
} | ||
return this.pattern.IsMatch(stdout) || this.pattern.IsMatch(stderr); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.