Skip to content

Prediction engine options #5964

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

Merged
merged 6 commits into from
Oct 12, 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
Prev Previous commit
Next Next commit
Fixed Test
  • Loading branch information
michaelgsharp committed Oct 9, 2021
commit abb51654151b294620cb4fedec6e1f1b33ac41d8
14 changes: 11 additions & 3 deletions test/Microsoft.ML.IntegrationTests/Prediction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.ML.Calibrators;
using Microsoft.ML.Data;
using Microsoft.ML.IntegrationTests.Datasets;
Expand Down Expand Up @@ -111,8 +112,12 @@ public void PredictionEngineModelDisposal()
// Dispose of prediction engine, should dispose of model
engine.Dispose();

// Attempt to dispose of model but it should already be disposed.
Assert.Throws<ObjectDisposedException>(() => model.Dispose());
// Get disposed flag using reflection
var bfIsDisposed = BindingFlags.Instance | BindingFlags.NonPublic;
var field = model.GetType().BaseType.BaseType.GetField("_disposed", bfIsDisposed);

// Make sure the model is actually disposed
Assert.True((bool)field.GetValue(model));

// Make a new model/prediction engine. Set the options so prediction engine doesn't dispose
model = pipeline.Fit(data);
Expand All @@ -127,7 +132,10 @@ public void PredictionEngineModelDisposal()
// Dispose of prediction engine, shoudln't dispose of model
engine.Dispose();

// Manually dispose of model, no errors are thrown
// Make sure model is not disposed of.
Assert.False((bool)field.GetValue(model));

// Dispose of the model for test cleanliness
model.Dispose();
}
}
Expand Down