Skip to content

Commit

Permalink
revert the wrong CreateForValidation change; better tests for #116
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Mar 26, 2023
1 parent 8a90401 commit 97ae62f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/DryIoc/Container.cs
Expand Up @@ -9561,7 +9561,7 @@ internal static Request CreateForValidation(Container container, ServiceInfo ser
{
var req = RentRequestOrNull();
return req == null
? new Request(container, Empty, 1, 0, depRequestStack, RequestFlags.IsResolutionCall, serviceInfo, serviceInfo.GetActualServiceType(), null)
? req = new Request(container, Empty, 1, 0, depRequestStack, RequestFlags.IsResolutionCall, serviceInfo, serviceInfo.GetActualServiceType(), null)
: req.SetServiceInfo(container, Empty, 1, 0, depRequestStack, RequestFlags.IsResolutionCall, serviceInfo, serviceInfo.GetActualServiceType(), null);
}

Expand Down
Expand Up @@ -18,49 +18,43 @@ interface IQuery<T> { }
class Query<T> : IQuery<T> { };
class QueryDecorator<T> : IQuery<T>
{
public QueryDecorator(IQuery<T> decoratee) { }
public readonly IQuery<T> Decoratee;
public QueryDecorator(IQuery<T> decoratee) => Decoratee = decoratee;
}

public async Task DryIoc_Resolve_parallel_execution_on_repeat(int repeatCount)
{
for (var i = 0; i < repeatCount; i++)
await DryIoc_Resolve_parallel_execution();
await DryIoc_Resolve_parallel_execution(i);
}

// [Test, Repeat(10)]
public async Task DryIoc_Resolve_parallel_execution()
public async Task DryIoc_Resolve_parallel_execution(int iter)
{
var container = new Container();
var container = new Container(Rules.Default.WithoutInterpretationForTheFirstResolution());

container.Register(typeof(IQuery<string>), typeof(Query<string>));
container.Register(typeof(IQuery<string>), typeof(Query<string>));
container.Register(typeof(IQuery<string>), typeof(QueryDecorator<string>), setup: Setup.Decorator);

IQuery<string> ResolveInScope()
{
using (var scope = container.OpenScope())
{
return scope.Resolve<IQuery<string>>();
}
}

// const int tasksCount = 1;
const int tasksCount = 32;

var tasks = new Task<IQuery<string>>[tasksCount];
for (var i = 0; i < tasks.Length; i++)
tasks[i] = Task.Run(() => ResolveInScope());
tasks[i] = Task.Run(() => container.Resolve<IQuery<string>>());

await Task.WhenAll(tasks);

var failed = false;
var sb = new StringBuilder(tasks.Length);
for (var i = 0; i < tasks.Length; i++)
{
var success = tasks[i].Result is QueryDecorator<string>;
if (!success) failed = true;
var success = tasks[i].Result is QueryDecorator<string> r && r.Decoratee is QueryDecorator<string> == false;
failed |= !success;
sb.Append(success ? '_' : 'F');
}

Assert.IsFalse(failed, $"Some tasks are failed [{sb}]");
Assert.IsFalse(failed, $"Some of {tasks.Length} tasks are failed [{sb}] on iteration {iter}");
}
}
}

0 comments on commit 97ae62f

Please sign in to comment.