Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GetUser returning wrong users for alias #89

Merged
merged 4 commits into from
Jun 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ public class TestConfiguration

private const string GetUserException = "Unable to retrieve user configuration. Please ensure a user with the given alias exists in the config.";

[ThreadStatic]
private static UserConfiguration currentUser;
private readonly object userEnumeratorsLock = new object();
private readonly ThreadLocal<UserConfiguration> currentUser = new ThreadLocal<UserConfiguration>();
private Dictionary<string, IEnumerator<UserConfiguration>> userEnumerators;
private string profilesBasePath;

Expand Down Expand Up @@ -107,9 +108,9 @@ public Uri GetTestUrl()
/// <returns>The user configuration.</returns>
public UserConfiguration GetUser(string userAlias, bool useCurrentUser = true)
{
if (useCurrentUser && this.currentUser.Value != null)
if (useCurrentUser && currentUser != null && currentUser.Alias == userAlias)
ewingjm marked this conversation as resolved.
Show resolved Hide resolved
{
return this.currentUser.Value;
return currentUser;
}

try
Expand All @@ -124,15 +125,15 @@ public UserConfiguration GetUser(string userAlias, bool useCurrentUser = true)
aliasEnumerator.MoveNext();
}

this.currentUser.Value = aliasEnumerator.Current;
currentUser = aliasEnumerator.Current;
}
}
catch (Exception ex)
{
throw new ConfigurationErrorsException($"{GetUserException} User: {userAlias}", ex);
}

return this.currentUser.Value;
return currentUser;
}
}
}