@@ -940,8 +940,8 @@ TEST_F(ShmManagerTestSysV, TestMappingAlignment) {
940940}
941941
942942// Verify that ShmManager can attach to segments created with the old
943- // (fnv64_BROKEN) hash, and that newly created segments also use the old hash
944- // (for backward-compatibility until we create new segments with xxhash3) .
943+ // (fnv64_BROKEN) hash, but that newly created segments use the new (xxhash3)
944+ // hash .
945945void ShmManagerTest::testHashMigrationWarmRoll (bool posix) {
946946 // fnv64_BROKEN and xxhash3 produce different hashes for any input.
947947 // Use a path with a high byte to be safe.
@@ -1007,8 +1007,7 @@ void ShmManagerTest::testHashMigrationWarmRoll(bool posix) {
10071007 }
10081008
10091009 // Phase 2: Create a new ShmManager. It should attach to the old-hash
1010- // segments, and any newly created segment should also use the old hash
1011- // (for backward-compatibility during migration).
1010+ // segments, but any newly created segment should use the new hash.
10121011 {
10131012 ShmManager s (migrationDir, posix);
10141013 auto baseline = ShmManager::getNumOldHashAttaches ();
@@ -1023,7 +1022,7 @@ void ShmManagerTest::testHashMigrationWarmRoll(bool posix) {
10231022 ASSERT_EQ (baseline + 2 , ShmManager::getNumOldHashAttaches ());
10241023
10251024 // Create a brand-new segment (e.g. shm_info on first warm roll after
1026- // migration). This should still use the old hash for backward compat .
1025+ // migration). This should now use the new hash.
10271026 s.createShm (segNew, size);
10281027 ASSERT_EQ (baseline + 2 , ShmManager::getNumOldHashAttaches ());
10291028
@@ -1036,15 +1035,14 @@ void ShmManagerTest::testHashMigrationWarmRoll(bool posix) {
10361035 ASSERT_THROW (ShmSegment (ShmAttach, newId1, posix), std::system_error);
10371036 ASSERT_THROW (ShmSegment (ShmAttach, newId2, posix), std::system_error);
10381037
1039- // Verify: new segment exists under the old hash name only (write path
1040- // uses fnv64_BROKEN during migration ).
1038+ // Verify: new segment exists under the new hash name only (write path
1039+ // now uses xxhash3 ).
10411040 ASSERT_NO_THROW (ShmSegment (
1042- ShmAttach, ShmManager::oldUniqueIdForName (segNew, migrationDir),
1043- posix));
1044- ASSERT_THROW (ShmSegment (ShmAttach,
1045- ShmManager::uniqueIdForName (segNew, migrationDir),
1046- posix),
1047- std::system_error);
1041+ ShmAttach, ShmManager::uniqueIdForName (segNew, migrationDir), posix));
1042+ ASSERT_THROW (
1043+ ShmSegment (ShmAttach,
1044+ ShmManager::oldUniqueIdForName (segNew, migrationDir), posix),
1045+ std::system_error);
10481046
10491047 ASSERT_TRUE (s.shutDown () == ShutDownRes::kSuccess );
10501048 }
@@ -1065,7 +1063,9 @@ void ShmManagerTest::testHashMigrationWarmRoll(bool posix) {
10651063 ASSERT_EQ (baseline + 2 , ShmManager::getNumOldHashAttaches ());
10661064
10671065 ASSERT_NO_THROW (s.attachShm (segNew));
1068- ASSERT_EQ (baseline + 3 , ShmManager::getNumOldHashAttaches ());
1066+ // segNew was created with new hash, so attaching to it should NOT increment
1067+ // the counter
1068+ ASSERT_EQ (baseline + 2 , ShmManager::getNumOldHashAttaches ());
10691069
10701070 ASSERT_TRUE (s.shutDown () == ShutDownRes::kSuccess );
10711071 }
@@ -1085,8 +1085,7 @@ TEST_F(ShmManagerTestSysV, HashMigrationWarmRoll) {
10851085}
10861086
10871087// Verify that when shared memory segments are wiped (simulating a machine
1088- // restart), all segments are created with the old (fnv64_BROKEN) hash
1089- // for backward-compatibility during migration.
1088+ // restart), all segments are created with the new (xxhash3) hash.
10901089void ShmManagerTest::testHashMigrationColdStart (bool posix) {
10911090 // Use a path with a high byte so fnv64_BROKEN != xxhash3.
10921091 const std::string migrationDir = cacheDir + std::string (1 , ' \x80 ' );
@@ -1121,30 +1120,31 @@ void ShmManagerTest::testHashMigrationColdStart(bool posix) {
11211120
11221121 ASSERT_EQ (baseline, ShmManager::getNumOldHashAttaches ());
11231122
1124- // Verify: segments exist under old hash names only (write path uses
1125- // fnv64_BROKEN during migration ).
1126- ASSERT_NO_THROW (ShmSegment (ShmAttach, oldId1 , posix));
1127- ASSERT_NO_THROW (ShmSegment (ShmAttach, oldId2 , posix));
1123+ // Verify: segments exist under new hash names only (write path now uses
1124+ // xxhash3 ).
1125+ ASSERT_NO_THROW (ShmSegment (ShmAttach, newId1 , posix));
1126+ ASSERT_NO_THROW (ShmSegment (ShmAttach, newId2 , posix));
11281127
1129- // Verify: segments do NOT exist under new hash names.
1130- ASSERT_THROW (ShmSegment (ShmAttach, newId1 , posix), std::system_error);
1131- ASSERT_THROW (ShmSegment (ShmAttach, newId2 , posix), std::system_error);
1128+ // Verify: segments do NOT exist under old hash names.
1129+ ASSERT_THROW (ShmSegment (ShmAttach, oldId1 , posix), std::system_error);
1130+ ASSERT_THROW (ShmSegment (ShmAttach, oldId2 , posix), std::system_error);
11321131
11331132 ASSERT_TRUE (s.shutDown () == ShutDownRes::kSuccess );
11341133 }
11351134
1136- // Re-attach after shutdown - should work using old hash fallback .
1135+ // Re-attach after shutdown - should work using new hash.
11371136 {
11381137 ShmManager s (migrationDir, posix);
11391138 auto baseline = ShmManager::getNumOldHashAttaches ();
11401139
11411140 auto m1 = s.attachShm (seg1);
11421141 checkMemory (m1.addr , m1.size , magicVal);
1143- ASSERT_EQ (baseline + 1 , ShmManager::getNumOldHashAttaches ());
1142+ // Attaching to new-hash segment should NOT increment counter
1143+ ASSERT_EQ (baseline, ShmManager::getNumOldHashAttaches ());
11441144
11451145 auto m2 = s.attachShm (seg2);
11461146 checkMemory (m2.addr , m2.size , magicVal + 1 );
1147- ASSERT_EQ (baseline + 2 , ShmManager::getNumOldHashAttaches ());
1147+ ASSERT_EQ (baseline, ShmManager::getNumOldHashAttaches ());
11481148
11491149 ASSERT_TRUE (s.shutDown () == ShutDownRes::kSuccess );
11501150 }
0 commit comments