Skip to content

Commit

Permalink
Fix DateTime handling in Storage.cs and add hitl.db to OptunaTests.cs…
Browse files Browse the repository at this point in the history
…proj
  • Loading branch information
hrntsm committed Feb 28, 2024
1 parent 980bbaa commit 219f676
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Optuna/Storage/RDB/Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,14 @@ public Trial.Trial GetTrial(int trialId)
{
while (reader.Read())
{
DateTime completeTime = reader.GetValue(3) is DBNull ? DateTime.MaxValue : reader.GetDateTime(3);
trial = new Trial.Trial
{
TrialId = trialId,
Number = reader.GetInt32(0),
State = (TrialState)Enum.Parse(typeof(TrialState), reader.GetString(1), true),
DatetimeStart = reader.GetDateTime(2),
DatetimeComplete = reader.GetDateTime(3)
DatetimeComplete = completeTime
};
}
}
Expand Down
3 changes: 3 additions & 0 deletions OptunaTests/OptunaTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<None Update="TestFile\sqlite.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="TestFile\hitl.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
10 changes: 10 additions & 0 deletions OptunaTests/Storage/RDB/StorageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SqliteStorageTests : IClassFixture<CreateStorage>, IDisposable
{
private readonly string _createFilePath = @"TestFile/created.db";
private readonly string _existFilePath = @"TestFile/sqlite.db";
private readonly string _hitlFilePath = @"TestFile/hitl.db";
private readonly List<string> _tempDBPaths = new List<string>();

[Fact()]
Expand Down Expand Up @@ -86,6 +87,15 @@ public void GetAllStudiesTest()
Assert.Equal(3, studies.Length);
}

[Fact()]
public void LoadHitlDBTest()
{
var storage = new SqliteStorage(_hitlFilePath);
Study.Study[] study = storage.GetAllStudies();
Assert.Single(study);
Assert.Equal(DateTime.MinValue, study[0].Trials[0].DatetimeComplete);
}

public void Dispose()
{
foreach (string path in _tempDBPaths)
Expand Down
Binary file added OptunaTests/TestFile/hitl.db
Binary file not shown.

0 comments on commit 219f676

Please sign in to comment.