Skip to content
This repository has been archived by the owner on Oct 26, 2018. It is now read-only.

Add to Visited if in Cache #69

Merged
merged 7 commits into from
Jun 6, 2017
Merged

Add to Visited if in Cache #69

merged 7 commits into from
Jun 6, 2017

Conversation

jbagga
Copy link
Contributor

@jbagga jbagga commented Jun 2, 2017

Attempt to address aspnet/Mvc#6292

cc @rynowak

if (!isError && !context.Visited.ContainsKey(key))
{
context.Visited.Add(key, verificationResult);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this condition is correct. We should always add the verification result here.

We already know that context.Visited.ContainsKey(key) returns false (Line 97).

We also want to maintain the postcondition that everything we look at is in context.Visited, so it should go in there regardless of whether it's an error.

@jbagga
Copy link
Contributor Author

jbagga commented Jun 2, 2017

@rynowak Updated

if (context.Cache.TryGetValue(key, out cacheResult))
{
context.Visited.Add(key, verificationResult);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we also need to copy the related properties from catchResult -> verificationResult

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 69 also need to change to a 'TryAdd`.

Basically we need to deal with the fact that we could find out from this method that our proxy type as already been created.

@jbagga
Copy link
Contributor Author

jbagga commented Jun 6, 2017

@rynowak Updated

if (context.Cache.TryGetValue(key, out cacheResult))
{
verificationResult.Constructor = cacheResult.Constructor;
verificationResult.Type = cacheResult.Type;
context.Visited.Add(key, verificationResult);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line after this, it's bad Feng Shui to put a comment directly between two lines of code.

if (context.Cache.TryGetValue(key, out cacheResult))
{
verificationResult.Constructor = cacheResult.Constructor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment here, this should explain how/why this can happen.

var key = new Tuple<Type, Type>(sourceType, targetType);
var cache = new ProxyTypeCache();
cache[key] = ProxyTypeCacheResult.FromType(key, sourceType, sourceType.GetConstructor(Array.Empty<Type>()));
var context = new ProxyTypeEmitter.ProxyBuilderContext(cache, targetType, sourceType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let it breathe.

public void GetProxyType_IfAlreadyInCache_AlsoAddedToVisited_FromType()
{
// Arrange
var sourceType = typeof(ProxyPerson);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you pick an example that should at least by possible?

@jbagga
Copy link
Contributor Author

jbagga commented Jun 6, 2017

@rynowak Updated

if (context.Cache.TryGetValue(key, out cacheResult))
{
// If we have a key in the cache because of an operation that completed before,
// but context.Visited.ContainsKey(key) above returned false, then we must add the key
// to the context.Visited list.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments should say why not what

Copy link
Member

@rynowak rynowak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with a reword of that comment

@jbagga jbagga merged commit f035508 into dev Jun 6, 2017
@jbagga jbagga deleted the jbagga/ProxyTypeEmitter branch June 6, 2017 21:42
rynowak pushed a commit that referenced this pull request Aug 25, 2017
Addresses possible race condition in aspnet/Mvc#6292

(cherry picked from commit f035508)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants