Skip to content

Conversation

@PanWuming
Copy link

@PanWuming PanWuming commented Jun 12, 2024

Description

This PR adds four unit tests to handle scenarios where LiteDB attempts to open invalid database files and streams:

  • Test_AddDatabase_InvalidDatabase: Tests handling of a file with invalid content.
  • Test_AddDatabase_InvalidDatabase_LargeFile: Tests handling of a file with invalid content larger than 16KB.
  • Test_AddDatabase_InvalidDatabase_MemoryStream: Tests handling of an invalid content stream.
  • Test_AddDatabase_InvalidDatabase_LargeFile_MemoryStream: Tests handling of a large invalid content stream.

Issues

These tests are intended to address issue #2501.

Bugs Discovered

  1. Test_AddDatabase_InvalidDatabase:

    • Bug: The test expected a LiteDB.LiteException to be thrown.
    • Actual: No exception was thrown.
    • Details:
      Assert.Throws() Failure
      Expected: typeof(LiteDB.LiteException)
      Actual:   (No exception was thrown)
      
      
  2. Test_AddDatabase_InvalidDatabase_LargeFile:

    • Bug: The test expected a LiteDB.LiteException to be thrown.
    • Actual: A System.ArgumentOutOfRangeException was thrown.
    • Details:
      Assert.Throws() Failure
      Expected: typeof(LiteDB.LiteException)
      Actual:   typeof(System.ArgumentOutOfRangeException): Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. (Parameter 'ticks')
      
  3. Test_AddDatabase_InvalidDatabase_MemoryStream:

    • Bug: The test expected a LiteDB.LiteException to be thrown.
    • Actual: A System.NotSupportedException was thrown.
    • Details:
      Assert.IsType() Failure
      Expected: LiteDB.LiteException
      Actual:   System.NotSupportedException
      
  4. Test_AddDatabase_InvalidDatabase_LargeFile_MemoryStream:

    • Bug: The test expected a LiteDB.LiteException to be thrown.
    • Actual: A System.ArgumentOutOfRangeException was thrown.
    • Details:
      Assert.IsType() Failure
      Expected: LiteDB.LiteException
      Actual:   System.ArgumentOutOfRangeException
      

These findings indicate that LiteDB is not handling invalid files and streams as expected, leading to different types of exceptions or no exceptions at all.

@JKamsker
Copy link
Collaborator

Does it also work with memorystreams? I prefer not to write on my disk.

@PanWuming
Copy link
Author

Does it also work with memorystreams? I prefer not to write on my disk.

Thank you for your feedback. I have updated the PR with the requested MemoryStream tests and included exception outputs for debugging. Please review the latest changes.

Copy link
Collaborator

@mbdavid mbdavid left a comment

Choose a reason for hiding this comment

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

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants