Skip to content

Commit

Permalink
Bump dependencies and fix warnings and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
khellang authored and ragnarstolsmark committed Oct 18, 2023
1 parent 6c3972b commit 3049a76
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 78 deletions.
4 changes: 2 additions & 2 deletions src/Hangfire.Console/Hangfire.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Hangfire.Core" Version="1.6.0" />
<PackageReference Include="JetBrains.Annotations" Version="11.0.0" PrivateAssets="All" />
<PackageReference Include="Hangfire.Core" Version="1.8.5" />
<PackageReference Include="JetBrains.Annotations" Version="2023.2.0" PrivateAssets="All" />
</ItemGroup>
</Project>
24 changes: 12 additions & 12 deletions src/Hangfire.Console/Storage/ConsoleStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public ConsoleStorage(IStorageConnection connection)

if (!(connection is JobStorageConnection jobStorageConnection))
throw new NotSupportedException("Storage connections must implement JobStorageConnection");

_connection = jobStorageConnection;
}

Expand All @@ -41,9 +41,9 @@ public void InitConsole(ConsoleId consoleId)
{
if (!(transaction is JobStorageTransaction))
throw new NotSupportedException("Storage tranactions must implement JobStorageTransaction");

transaction.SetRangeInHash(consoleId.GetHashKey(), new[] { new KeyValuePair<string, string>("jobId", consoleId.JobId) });

transaction.Commit();
}
}
Expand All @@ -56,7 +56,7 @@ public void AddLine(ConsoleId consoleId, ConsoleLine line)
throw new ArgumentNullException(nameof(line));
if (line.IsReference)
throw new ArgumentException("Cannot add reference directly", nameof(line));

using (var tran = _connection.CreateWriteTransaction())
{
// check if encoded message fits into Set's Value field
Expand All @@ -72,14 +72,14 @@ public void AddLine(ConsoleId consoleId, ConsoleLine line)
else
{
// try to encode and see if it fits
value = JobHelper.ToJson(line);
value = SerializationHelper.Serialize(line);

if (value.Length > ValueFieldLimit)
{
value = null;
}
}

if (value == null)
{
var referenceKey = Guid.NewGuid().ToString("N");
Expand All @@ -89,22 +89,22 @@ public void AddLine(ConsoleId consoleId, ConsoleLine line)
line.Message = referenceKey;
line.IsReference = true;

value = JobHelper.ToJson(line);
value = SerializationHelper.Serialize(line);
}

tran.AddToSet(consoleId.GetSetKey(), value, line.TimeOffset);

if (line.ProgressValue.HasValue && line.Message == "1")
{
var progress = line.ProgressValue.Value.ToString(CultureInfo.InvariantCulture);

tran.SetRangeInHash(consoleId.GetHashKey(), new[] { new KeyValuePair<string, string>("progress", progress) });
}

tran.Commit();
}
}

public TimeSpan GetConsoleTtl(ConsoleId consoleId)
{
if (consoleId == null)
Expand Down Expand Up @@ -162,7 +162,7 @@ public IEnumerable<ConsoleLine> GetLines(ConsoleId consoleId, int start, int end

foreach (var item in items)
{
var line = JobHelper.FromJson<ConsoleLine>(item);
var line = SerializationHelper.Deserialize<ConsoleLine>(item);

if (line.IsReference)
{
Expand All @@ -183,7 +183,7 @@ public IEnumerable<ConsoleLine> GetLines(ConsoleId consoleId, int start, int end
{
line.Message = _connection.GetValueFromHash(consoleId.GetHashKey(), line.Message);
}

line.IsReference = false;
}

Expand Down
12 changes: 9 additions & 3 deletions tests/Hangfire.Console.Tests/ConsoleExtensionsFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ public class ConsoleExtensionsFacts
private readonly Mock<IJobCancellationToken> _cancellationToken;
private readonly Mock<JobStorageConnection> _connection;
private readonly Mock<JobStorageTransaction> _transaction;
private readonly Mock<JobStorage> _jobStorage;

public ConsoleExtensionsFacts()
{
_cancellationToken = new Mock<IJobCancellationToken>();
_connection = new Mock<JobStorageConnection>();
_transaction = new Mock<JobStorageTransaction>();
_jobStorage = new Mock<JobStorage>();

_connection.Setup(x => x.CreateWriteTransaction())
.Returns(_transaction.Object);
}

[Fact]
public void WriteLine_DoesNotFail_IfContextIsNull()
{
Expand Down Expand Up @@ -71,7 +73,7 @@ public void WriteProgressBar_ReturnsProgressBar_IfConsoleCreated()
context.Items["ConsoleContext"] = CreateConsoleContext(context);

var progressBar = ConsoleExtensions.WriteProgressBar(context);

Assert.IsType<DefaultProgressBar>(progressBar);
_transaction.Verify(x => x.Commit());
}
Expand All @@ -87,13 +89,17 @@ public void WriteProgressBar_ReturnsNoOp_IfConsoleNotCreated()
_transaction.Verify(x => x.Commit(), Times.Never);
}

#pragma warning disable xUnit1013
public static void JobMethod()
#pragma warning restore xUnit1013
{
}

private PerformContext CreatePerformContext()
{
return new PerformContext(_connection.Object,
return new PerformContext(
_jobStorage.Object,
_connection.Object,
new BackgroundJob("1", Common.Job.FromExpression(() => JobMethod()), DateTime.UtcNow),
_cancellationToken.Object);
}
Expand Down
52 changes: 26 additions & 26 deletions tests/Hangfire.Console.Tests/Dashboard/ConsoleRendererFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void RenderText_Empty()

Assert.Equal("", builder.ToString());
}

[Fact]
public void RenderText_Simple()
{
Expand All @@ -46,7 +46,7 @@ public void RenderText_Simple()

Assert.Equal("test", builder.ToString());
}

[Fact]
public void RenderText_HtmlEncode()
{
Expand All @@ -57,7 +57,7 @@ public void RenderText_HtmlEncode()

Assert.Equal("&lt;bolts &amp; nuts&gt;", builder.ToString());
}

[Fact]
public void RenderText_Hyperlink()
{
Expand All @@ -77,9 +77,9 @@ public void RenderLine_Basic()

ConsoleRenderer.RenderLine(builder, line, new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));

Assert.Equal("<div class=\"line\"><span data-moment-title=\"1451606400\">+ <1ms</span>test</div>", builder.ToString());
Assert.Equal("<div class=\"line\"><span data-moment-title=\"1451606400\">+ &lt;1ms</span>test</div>", builder.ToString());
}

[Fact]
public void RenderLine_WithOffset()
{
Expand All @@ -101,7 +101,7 @@ public void RenderLine_WithNegativeOffset()

Assert.Equal("<div class=\"line\"><span data-moment-title=\"1451606398\">-1.206s</span>test</div>", builder.ToString());
}

[Fact]
public void RenderLine_WithColor()
{
Expand All @@ -110,7 +110,7 @@ public void RenderLine_WithColor()

ConsoleRenderer.RenderLine(builder, line, new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));

Assert.Equal("<div class=\"line\" style=\"color:#ffffff\"><span data-moment-title=\"1451606400\">+ <1ms</span>test</div>", builder.ToString());
Assert.Equal("<div class=\"line\" style=\"color:#ffffff\"><span data-moment-title=\"1451606400\">+ &lt;1ms</span>test</div>", builder.ToString());
}

[Fact]
Expand All @@ -121,9 +121,9 @@ public void RenderLine_WithProgress()

ConsoleRenderer.RenderLine(builder, line, new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));

Assert.Equal("<div class=\"line pb\" data-id=\"3\"><span data-moment-title=\"1451606400\">+ <1ms</span><div class=\"pv\" style=\"width:17%\" data-value=\"17\"></div></div>", builder.ToString());
Assert.Equal("<div class=\"line pb\" data-id=\"3\"><span data-moment-title=\"1451606400\">+ &lt;1ms</span><div class=\"pv\" style=\"width:17%\" data-value=\"17\"></div></div>", builder.ToString());
}

[Fact]
public void RenderLine_WithProgressName()
{
Expand All @@ -132,9 +132,9 @@ public void RenderLine_WithProgressName()

ConsoleRenderer.RenderLine(builder, line, new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));

Assert.Equal("<div class=\"line pb\" data-id=\"3\"><span data-moment-title=\"1451606400\">test &lt;go&gt;</span><div class=\"pv\" style=\"width:17%\" data-value=\"17\"></div></div>", builder.ToString());
Assert.Equal("<div class=\"line pb\" data-id=\"3\"><span data-moment-title=\"1451606400\">test &amp;lt;go&amp;gt;</span><div class=\"pv\" style=\"width:17%\" data-value=\"17\"></div></div>", builder.ToString());
}

[Fact]
public void RenderLine_WithFractionalProgress()
{
Expand All @@ -143,7 +143,7 @@ public void RenderLine_WithFractionalProgress()

ConsoleRenderer.RenderLine(builder, line, new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));

Assert.Equal("<div class=\"line pb\" data-id=\"3\"><span data-moment-title=\"1451606400\">+ <1ms</span><div class=\"pv\" style=\"width:17.3%\" data-value=\"17\"></div></div>", builder.ToString());
Assert.Equal("<div class=\"line pb\" data-id=\"3\"><span data-moment-title=\"1451606400\">+ &lt;1ms</span><div class=\"pv\" style=\"width:17.3%\" data-value=\"17\"></div></div>", builder.ToString());
}

[Fact]
Expand All @@ -154,9 +154,9 @@ public void RenderLine_WithProgressAndColor()

ConsoleRenderer.RenderLine(builder, line, new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));

Assert.Equal("<div class=\"line pb\" style=\"color:#ffffff\" data-id=\"3\"><span data-moment-title=\"1451606400\">+ <1ms</span><div class=\"pv\" style=\"width:17%\" data-value=\"17\"></div></div>", builder.ToString());
Assert.Equal("<div class=\"line pb\" style=\"color:#ffffff\" data-id=\"3\"><span data-moment-title=\"1451606400\">+ &lt;1ms</span><div class=\"pv\" style=\"width:17%\" data-value=\"17\"></div></div>", builder.ToString());
}

[Fact]
public void RenderLines_ThrowsException_IfBuilderIsNull()
{
Expand All @@ -180,20 +180,20 @@ public void RenderLines_RendersNothing_IfLinesIsEmpty()

Assert.Equal(0, builder.Length);
}

[Fact]
public void RenderLines_RendersAllLines()
{
var builder = new StringBuilder();
ConsoleRenderer.RenderLines(builder, new[]
ConsoleRenderer.RenderLines(builder, new[]
{
new ConsoleLine() { TimeOffset = 0, Message = "line1" },
new ConsoleLine() { TimeOffset = 1, Message = "line2" }
}, new DateTime(2016, 1, 1, 0, 0, 0, DateTimeKind.Utc));

Assert.Equal(
"<div class=\"line\"><span data-moment-title=\"1451606400\">+ <1ms</span>line1</div>" +
"<div class=\"line\"><span data-moment-title=\"1451606401\">+1s</span>line2</div>",
"<div class=\"line\"><span data-moment-title=\"1451606400\">+ &lt;1ms</span>line1</div>" +
"<div class=\"line\"><span data-moment-title=\"1451606401\">+1s</span>line2</div>",
builder.ToString());
}

Expand Down Expand Up @@ -225,24 +225,24 @@ public void RenderLineBuffer_RendersEmpty_WithNegativeN_IfStartIsNegative()

Assert.Equal("<div class=\"line-buffer\" data-n=\"-1\"></div>", builder.ToString());
}

[Fact]
public void RenderLineBuffer_RendersAllLines_IfStartIsZero()
{
SetupStorage(CreateState(ProcessingState.StateName, _consoleId.DateValue),
new ConsoleLine() { TimeOffset = 0, Message = "line1" },
new ConsoleLine() { TimeOffset = 1, Message = "line2" });

var builder = new StringBuilder();
ConsoleRenderer.RenderLineBuffer(builder, _storage.Object, _consoleId, 0);

Assert.Equal(
"<div class=\"line-buffer\" data-n=\"2\">" +
"<div class=\"line\"><span data-moment-title=\"1451606400\">+ <1ms</span>line1</div>" +
"<div class=\"line\"><span data-moment-title=\"1451606400\">+ &lt;1ms</span>line1</div>" +
"<div class=\"line\"><span data-moment-title=\"1451606401\">+1s</span>line2</div>" +
"</div>", builder.ToString());
}

[Fact]
public void RenderLineBuffer_RendersLines_FromStartOffset()
{
Expand Down Expand Up @@ -278,7 +278,7 @@ public void RenderLineBuffer_RendersEmpty_WithMinusTwo_IfStateNotFound()
SetupStorage(null,
new ConsoleLine() { TimeOffset = 0, Message = "line1" },
new ConsoleLine() { TimeOffset = 1, Message = "line2" });

var builder = new StringBuilder();
ConsoleRenderer.RenderLineBuffer(builder, _storage.Object, _consoleId, 2);

Expand Down Expand Up @@ -318,17 +318,17 @@ public void RenderLineBuffer_AggregatesMultipleProgressLines()
new ConsoleLine() { TimeOffset = 0, Message = "0", ProgressValue = 1 },
new ConsoleLine() { TimeOffset = 1, Message = "1", ProgressValue = 3 },
new ConsoleLine() { TimeOffset = 2, Message = "0", ProgressValue = 5 });

var builder = new StringBuilder();
ConsoleRenderer.RenderLineBuffer(builder, _storage.Object, _consoleId, 0);

Assert.Equal(
"<div class=\"line-buffer\" data-n=\"3\">" +
"<div class=\"line pb\" data-id=\"0\"><span data-moment-title=\"1451606400\">+ <1ms</span><div class=\"pv\" style=\"width:5%\" data-value=\"5\"></div></div>" +
"<div class=\"line pb\" data-id=\"0\"><span data-moment-title=\"1451606400\">+ &lt;1ms</span><div class=\"pv\" style=\"width:5%\" data-value=\"5\"></div></div>" +
"<div class=\"line pb\" data-id=\"1\"><span data-moment-title=\"1451606401\">+1s</span><div class=\"pv\" style=\"width:3%\" data-value=\"3\"></div></div>" +
"</div>", builder.ToString());
}

private StateData CreateState(string stateName, DateTime startedAt)
{
return new StateData()
Expand Down
11 changes: 7 additions & 4 deletions tests/Hangfire.Console.Tests/Hangfire.Console.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="Moq" Version="4.7.99" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="Moq" Version="4.20.69" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 3049a76

Please sign in to comment.