- Notifications
You must be signed in to change notification settings - Fork748
Domain reload test cases fixes#1287
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Domain reload test cases fixes#1287
Uh oh!
There was an error while loading.Please reload this page.
Conversation
The tests are marked as expected failures for now.
Even though it tests nothing.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/runtime/maybeserialize.cs Outdated
string[] types = new string[p.Length]; | ||
for (int i = 0; i < p.Length; i++) | ||
{ | ||
types[i] = p[i].ParameterType.AssemblyQualifiedName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Does this work correctly forout
andref
parameters? There might be more edge cases.
Potentiallyin
parameters also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'll have to test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Did a quick check andout
andref
parameters both reflect tovoid function (SomeType ByRef)
with the type argument being of type(SomeType&, ...)
. Haven't been able to test within
(couldn't get to set the language version high enough inTestRunner.cs
), but it looks like it's doing the correct thing. Will add a test case for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ah, found an edge case where changingref
toout
will still "resolve" the function even though the semantics are now different
src/runtime/moduleobject.cs Outdated
// Trying to remove a key that's not in the dictionary may | ||
// raise an error. We don't care about it. | ||
Runtime.PyErr_Clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You must check for the specific error type after each call. SeePyObject.GetAttrOrDefault
for example.
src/runtime/typemanager.cs Outdated
var _cache = new Dictionary<MaybeType, IntPtr>(); | ||
storage.GetValue("cache", out _cache); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
the value you put into_cache
here will always be overwritten.
You can (and should) useout var _cache
.
src/runtime/typemanager.cs Outdated
catch | ||
{ | ||
Runtime.XDecref(entry.Value); | ||
continue; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Is there a specific exception we could handle?
Can the exception be avoided in the first place by adding a precheck?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
... adding a precheck?
Yes
Uh oh!
There was an error while loading.Please reload this page.
Serialization of System.Type, MemberInfo and MethodBase is now stringbased. At deserialization, use reflection to attempt to recreate theobject, which may fail safely instead of throwing aSerializaitonException during the deserialization of the whoie datastream. Appropriate Exceptions will now be raised when the Maybe*'sValue property.ClasseBase objects are now de-initialized and re-initialized in Reloadmode so that it's tp_dict picks up newly added members and removedmembers no longer linger.ModuleObject clears it's cache and remove cached members from it'stp_dict.Minor refactoring and modernization of MethodObject and MethodBinder
946107f
to3dad96e
CompareChanging a type's attribute causes problem with it's cache. Force thetype to refresh itself when modifying it.
* Revert line endings change in Python.Runtime.csproj* Split maybe serialize into respective class files* Name changes for consistency
codecov-io commentedNov 23, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## master #1287 +/- ##======================================= Coverage 74.04% 74.04% ======================================= Files 1 1 Lines 289 289 ======================================= Hits 214 214 Misses 75 75
Flags with carried forward coverage won't be shown.Click here to find out more. Continue to review full report at Codecov.
|
So that we can use that same logic when deserializing Maybe* types
// based on it's setter/getter (which is a method | ||
// info) visibility and events based on their | ||
// AddMethod visibility. | ||
static bool ShouldBindMember(MemberInfo mi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm not totally satisfied with this solution, but it's the best I could find. If anyone has a better idea..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
You could also leave this abstract and haveclass MaybePropertyInfo : MaybeMemberInfo<PropertyInfo>
and so on, enforcing that if the type of member changed then it doesn't count as a match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
But maybe that's not critical.
Serialization of System.Type, MemberInfo and MethodBase is now stringbased. At deserialization, use reflection to attempt to recreate theobject, which may fail safely instead of throwing aSerializaitonException during the deserialization of the whoie datastream. Appropriate Exceptions will now be raised when the Maybe*'sValue property.ClasseBase objects are now de-initialized and re-initialized in Reloadmode so that it's tp_dict picks up newly added members and removedmembers no longer linger.ModuleObject clears it's cache and remove cached members from it'stp_dict.Minor refactoring and modernization of MethodObject and MethodBinder
Changing a type's attribute causes problem with it's cache. Force thetype to refresh itself when modifying it.
* Revert line endings change in Python.Runtime.csproj* Split maybe serialize into respective class files* Name changes for consistency
So that we can use that same logic when deserializing Maybe* types
Because it can't find the python library
Because tp_clear sets tpHandle to NULL, it can't be used.Fortunately, we can simply read object's type from pyHandle.
… engine shutdown (pythonnet#1260)pythonnet#1256pythonnet#1256During engine shutdown all links from Python to .NET instances are severed. If an instance of CLR class defined in Python survives the shutdown (for example, a reference is stored in static field) and later gets finalized, it will attempt to severe link again, which is an invalid operation.The fix is to check if the link has already been severed and skip that step during finalization.
8639f09
to3069285
CompareBuild failures are due to NuGet hiccups
|
Uh oh!
There was an error while loading.Please reload this page.
}} | ||
}} | ||
"; | ||
readonly static string PythonDllLocation = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Python.Runtime.dll"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
NIT: I might be more reliable to dotypeof(Py).Assembly.Location
.
Uh oh!
There was an error while loading.Please reload this page.
src/domain_tests/TestRunner.cs Outdated
File.Delete(tempFolderPython); | ||
} | ||
File.Copy(PythonDllLocation, tempFolderPython); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
IMHO, the test should also delete the DLL.
I would also create a new folder (and delete after) for every run instead of always putting DLL directly in %TEMP%, because this might affect tests running in parallel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I totally agree with this
src/domain_tests/TestRunner.cs Outdated
CompilerParameters parameters = new CompilerParameters(); | ||
parameters.GenerateExecutable = exe; | ||
var assemblyName = name; | ||
var assemblyFullPath = Path.Combine(Path.GetTempPath(), assemblyName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Same: better have a run-specific folder.
Uh oh!
There was an error while loading.Please reload this page.
src/runtime/methodbinder.cs Outdated
if (mi == null) | ||
{ | ||
return -1; | ||
} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I thinkint.Max
would be more appropriate. Higher the number - lower the priority.
UPD. can this even be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
it could be null if we change the return type toint?
but it's not useful.int.Max
it is
src/runtime/methodobject.cs Outdated
} | ||
private void _MethodObject(Type type, string name, MethodInfo[] info) | ||
// `allow_threads = true`: True being the default value of MethodBinder.allow_threads |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Better use a constant.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
I'll be on holidays for two weeks, I'll fix that when back in office |
src/domain_tests/TestRunner.cs Outdated
static void SetupTestFolder(string testCaseName) | ||
{ | ||
TestPath = Path.Combine(Path.GetTempPath(), $"Python.TestRunner.{testCaseName}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think some random number should also be added to indicate the overall run, so that different runs would not clash.
BadSingletonJan 5, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
They wouldn't, if the folder exists when setting up the test, it gets deleted first. Also, the executable can only run one test per invocation. One could run all the tests in parallel, and there'd be no clashing. If a test fails, the folder is not deleted and the contents cans be examined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I still see a problem with running tests for multiple Python versions on the same machine in parallel.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Ah, I hadn't thought about that one. I'll add the python version and architecture to the folder name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'll add the PID instead
ac877c2
to5779d5f
CompareTo the test folder name
5779d5f
to73f39bc
Compare
What does this implement/fix? Explain your changes.
This PR adds the fixes for the xfail tests in#1275 .
Serialization of System.Type, MemberInfo and MethodBase is now string based. At de-serialization, use reflection to attempt to recreate the object, which now fails safely instead of throwing a SerializationException during the de-serialization of the whole data stream. Appropriate Exceptions will now be raised when the Maybe*'s Value property is accessed.
Does this close any currently open issues?
This addresses#957 and#1250 and offers an answer to#1268 .
Any other comments?
TODO: add changelog entries once the fixes are approved. Also, add docs on best practices with domain reloads.
Checklist
Check all those that are applicable and complete.
AUTHORS
CHANGELOG