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

Golden test suite for snapshot codec #499

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

recursion-ninja
Copy link
Collaborator

Description

Add the golden test cases to ensure that metadata serialization does not accidentally change. This will help ensure we maintain backwards compatibility. Changes in backwards compatibility should case test case failures.

@recursion-ninja
Copy link
Collaborator Author

So a big question I have is should this be a stand alone test suite (as it currently is) or should I graft it into the "monolithic" LST Tree test suite. I think the later might be more appropriate, and would appreciate a pointer as to where a good place in the TestTree to insert them.

Copy link
Collaborator

@jorisdral jorisdral left a comment

Choose a reason for hiding this comment

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

The new Bounded and Enum instances should arguably be orphan instances in the test suite. They are not necessary for the core library to function, or necessary for the user to have

@jorisdral jorisdral changed the title Recursion ninja/golden test suite Golden test suite for snapshot codec Dec 16, 2024
Copy link
Collaborator

@jorisdral jorisdral left a comment

Choose a reason for hiding this comment

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

Looking good. There are also some comments we discussed over other channels, but I won't repeat them here

lsm-tree.cabal Outdated Show resolved Hide resolved
test/codec-test.hs Outdated Show resolved Hide resolved
test/codec-test.hs Outdated Show resolved Hide resolved
test/codec-test.hs Outdated Show resolved Hide resolved
test/codec-test.hs Outdated Show resolved Hide resolved
test/codec-test.hs Outdated Show resolved Hide resolved
test/codec-test.hs Outdated Show resolved Hide resolved
test/codec-test.hs Outdated Show resolved Hide resolved
@recursion-ninja recursion-ninja force-pushed the recursion-ninja/golden-test-suite branch 3 times, most recently from 8b0d38e to 4c00cf4 Compare December 22, 2024 17:55
…e for serialization backwards compatibility testing.
@recursion-ninja recursion-ninja force-pushed the recursion-ninja/golden-test-suite branch from 4c00cf4 to 00e7a07 Compare December 30, 2024 15:57
Copy link
Collaborator

@jorisdral jorisdral left a comment

Choose a reason for hiding this comment

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

Almost LGTM! I do have some minor suggestions, but after that we can probably merge

@@ -70,7 +70,7 @@ instance RefCounted m (MergingRun m h) where
getRefCounter = mergeRefCounter

data MergePolicyForLevel = LevelTiering | LevelLevelling
deriving stock (Show, Eq)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you might have missed this suggestion: #499 (review)

Copy link
Collaborator

Choose a reason for hiding this comment

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

BTW, did we end up using these instances for the golden tests? It doesn't look like it -- if that's the case, let's remove these instances

@@ -47,6 +49,7 @@ tests = testGroup "Test.Database.LSMTree.Internal.Snapshot.Codec" [
testAll $ \(p :: Proxy a) ->
testGroup (show $ typeRep p) $
prop_arbitraryAndShrinkPreserveInvariant @a deepseqInvariant
, goldenFileTests
Copy link
Collaborator

Choose a reason for hiding this comment

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

The typical approach we use in this test suite is to include the tests at the top level, so in the Main module

-- |
-- Compare the serialization of snapshot metadata with a known reference file.
goldenFileTests :: TestTree
goldenFileTests = handleOutputFiles . testGroup "Golden File Comparisons" $
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
goldenFileTests = handleOutputFiles . testGroup "Golden File Comparisons" $
goldenFileTests = handleOutputFiles . testGroup "Test.Database.LSMTree.Internal.Snapshot.Codec.Golden" $

Comment on lines +30 to +31
-- |
-- Compare the serialization of snapshot metadata with a known reference file.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the newline intentional? Does haddock render it correctly?

import System.FS.IO (HandleIO, ioHasFS)
import qualified Test.Tasty as Tasty
import Test.Tasty (TestName, TestTree, testGroup)
import qualified Test.Tasty.Golden as Au
Copy link
Collaborator

Choose a reason for hiding this comment

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

Au as in the chemical symbol for gold? 😄

testCodecBuilder tName metadata =
testGroup tName $ uncurry snapshotCodecTest <$> metadata

type ComponentAnnotation = String
Copy link
Collaborator

Choose a reason for hiding this comment

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

It was not immediately clear to me what String is used for. Maybe add some documentation?

Comment on lines +152 to +156
enumerateSnapshotLabel :: [(ComponentAnnotation, SnapshotLabel)]
enumerateSnapshotLabel =
[ ("Bs", SnapshotLabel "UserProvidedLabel")
, ("Bn", SnapshotLabel "")
]
Copy link
Collaborator

Choose a reason for hiding this comment

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

So I think I understand now that the ComponentAnnotation is used to name the specific enumerations, and this is reflected in the names of the golden files. Can you explain how you picked these labels? And the labels for the other enumerators below?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants