Skip to content

Commit

Permalink
remove warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kbilsted committed Feb 1, 2024
1 parent fc54f2e commit 94335fd
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Demos/GreenFeetWorkFlow.Tests/AdoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void When_executing_step_throwing_exception_Then_rerun_current_step_and_e
helper.AssertTableCounts(helper.FlowId, ready: 1, done: 0, failed: 0);

var persister = helper.Persister;
var row = helper.Engine.Data.SearchSteps(new SearchModel(Id: dbid!.Value), StepStatus.Ready).Single();
var row = helper.Engine!.Data.SearchSteps(new SearchModel(Id: dbid!.Value), StepStatus.Ready).Single();
row!.State.Should().Be("\"hej\"");
row.FlowId.Should().Be(helper.FlowId);
row.Name.Should().Be(name);
Expand Down Expand Up @@ -276,7 +276,7 @@ public void When_one_step_executes_as_done_with_a_new_step_Then_new_step_has_the
}];
helper.StopWhenNoWork().BuildAndStart();

executingStep.FlowId.Should().Be(helper.FlowId);
executingStep!.FlowId.Should().Be(helper.FlowId);
executingStep.CorrelationId.Should().Be(helper.CorrelationId);
helper.AssertTableCounts(helper.FlowId, ready: 0, done: 2, failed: 0);
}
Expand Down
12 changes: 8 additions & 4 deletions src/Demos/GreenFeetWorkFlow.Tests/EngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void Setup()
}

[Test]
public async Task When_adding_an_event_Then_an_id_PK_is_returned()
public void When_adding_an_event_Then_an_id_PK_is_returned()
{
Step step = new Step(helper.RndName) { ScheduleTime = DateTime.Now.AddMonths(1) };

Expand Down Expand Up @@ -67,8 +67,9 @@ public async Task When_taskrun_a_sync_task_that_throws_an_exception_Then_we_cont
.ContinueWith(x =>
{
continued = true;
x.Exception.GetType().Should().Be<AggregateException>();
x.Exception.InnerException.Message.Should().Be(str);
x.IsFaulted.Should().BeTrue();
x.Exception!.GetType().Should().Be<AggregateException>();
x.Exception!.InnerException!.Message.Should().Be(str);
});
await t;
continued.Should().BeTrue();
Expand All @@ -80,7 +81,7 @@ public async Task When_taskrun_an_async_task_that_throws_an_exception_Then_we_co
{
var str = "some message";
bool continued = false;

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
Task t = Task
.Run(async () => { throw new Exception(str); })
.ContinueWith(x =>
Expand All @@ -92,6 +93,7 @@ public async Task When_taskrun_an_async_task_that_throws_an_exception_Then_we_co
});
await t;
continued.Should().BeTrue();
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
}

[Test]
Expand Down Expand Up @@ -156,7 +158,9 @@ public async Task When_taskfactory_an_async_task_from_that_throws_an_exception_T
continued.Should().BeFalse(); // notice await is not awaiting
}

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
static async Task SomeAsyncMethodThrowingException() => throw new Exception("foo");
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

/// <summary>
/// this is how we start tasks in the engine
Expand Down
4 changes: 2 additions & 2 deletions src/Demos/GreenFeetWorkFlow.Tests/PerformanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class PerformanceTests
[TestCase(50)] // 3 (local 00:00:00.5890152)
[TestCase(100)] // 5 (local 00:00:00.0149946)
[TestCase(200)] // 10 (local 00:00:00.0244962)
public async Task Inserting_10000_steps_timing(int max)
public void Inserting_10000_steps_timing(int max)
{
var helper = new TestHelper();

Expand Down Expand Up @@ -255,7 +255,7 @@ void doo(int workerCount)
stopwach.Stop();

int noElements = max;
Console.WriteLine($"Max Workers: {workerCount} Created:{testhelper.Engine.WorkerCoordinator.TotalWorkerCreated} Elapsed: {stopwach.ElapsedMilliseconds}ms Elements: {noElements} ~ {stopwach.ElapsedMilliseconds / (double)noElements} ms / per element and {noElements * 1000 / stopwach.ElapsedMilliseconds} pr. sec.\n\n");
Console.WriteLine($"Max Workers: {workerCount} Created:{testhelper.Engine!.WorkerCoordinator!.TotalWorkerCreated} Elapsed: {stopwach.ElapsedMilliseconds}ms Elements: {noElements} ~ {stopwach.ElapsedMilliseconds / (double)noElements} ms / per element and {noElements * 1000 / stopwach.ElapsedMilliseconds} pr. sec.\n\n");
}

doo(1);
Expand Down
29 changes: 17 additions & 12 deletions src/Product/GreenFeetWorkFlow.AdoPersistence/ObjectDataReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ private class PropertyAccessor
{
public List<Func<TData, object>> Accessors { get; set; }
public Dictionary<string, int> Lookup { get; set; }

public PropertyAccessor(List<Func<TData, object>> accessors, Dictionary<string, int> lookup)
{
Accessors = accessors;
Lookup = lookup;
}
}

private static readonly Lazy<PropertyAccessor> s_propertyAccessorCache = new Lazy<PropertyAccessor>(() =>
{
var propertyAccessors = typeof(TData)
.GetProperties(BindingFlags.Instance | BindingFlags.Public)
.Where(p => p.CanRead && p.CanWrite && p.Name!= "InitialState")
.Where(p => p.CanRead && p.CanWrite && p.Name != "InitialState")
.Select((p, i) => new
{
Index = i,
Expand All @@ -30,23 +36,22 @@ private class PropertyAccessor
})
.ToArray();

return new PropertyAccessor
{
Accessors = propertyAccessors.Select(p => p.Accessor).ToList(),
Lookup = propertyAccessors.ToDictionary(p => p.Property.Name, p => p.Index, StringComparer.OrdinalIgnoreCase)
};
return new PropertyAccessor(
propertyAccessors.Select(p => p.Accessor).ToList(),
propertyAccessors.ToDictionary(p => p.Property.Name, p => p.Index, StringComparer.OrdinalIgnoreCase)
);
});

private static Func<TData, object> CreatePropertyAccessor(PropertyInfo p)
{
var parameter = Expression.Parameter(typeof(TData), "input");
var propertyAccess = Expression.Property(parameter, p.GetGetMethod());
var propertyAccess = Expression.Property(parameter, p.GetGetMethod()!);
var castAsObject = Expression.TypeAs(propertyAccess, typeof(object));
var lamda = Expression.Lambda<Func<TData, object>>(castAsObject, parameter);
return lamda.Compile();
}

private IEnumerator<TData> m_dataEnumerator;
private IEnumerator<TData>? m_dataEnumerator;

public ObjectDataReader(IEnumerable<TData> data)
{
Expand All @@ -62,7 +67,7 @@ public void Close()

public int Depth => 1;

public DataTable GetSchemaTable()
public DataTable? GetSchemaTable()
{
return null;
}
Expand All @@ -78,7 +83,7 @@ public bool Read()
{
if (IsClosed)
throw new ObjectDisposedException(GetType().Name);
return m_dataEnumerator.MoveNext();
return m_dataEnumerator!.MoveNext();
}

public int RecordsAffected => -1;
Expand Down Expand Up @@ -138,7 +143,7 @@ public byte GetByte(int i)
throw new NotImplementedException();
}

public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
public long GetBytes(int i, long fieldOffset, byte[]? buffer, int bufferoffset, int length)
{
throw new NotImplementedException();
}
Expand All @@ -148,7 +153,7 @@ public char GetChar(int i)
throw new NotImplementedException();
}

public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
public long GetChars(int i, long fieldoffset, char[]? buffer, int bufferoffset, int length)
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Product/GreenFeetWorkFlow/WorkflowEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class WorkflowEngine
public string? EngineName { get; set; }
public CancellationToken StoppingToken { get; private set; }

public WorkerCoordinator WorkerCoordinator;
public WorkerCoordinator? WorkerCoordinator { get; private set; }

public WorkflowEngine(

Check warning on line 12 in src/Product/GreenFeetWorkFlow/WorkflowEngine.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Configuration' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
IWorkflowLogger logger,
Expand Down

0 comments on commit 94335fd

Please sign in to comment.