@@ -2001,3 +2001,56 @@ func TestHandlerFlippingHashrings(t *testing.T) {
20012001 cancel ()
20022002 wg .Wait ()
20032003}
2004+
2005+ // TestReplicationErrorsConflictScenario tests what happens in RF=3, Quorum=2
2006+ // when 1 replica is unavailable and 2 replicas return conflict errors.
2007+ func TestReplicationErrorsConflictScenario (t * testing.T ) {
2008+ t .Parallel ()
2009+
2010+ // Simulate RF=3, Quorum=2 scenario:
2011+ // - 1 replica returns unavailable
2012+ // - 2 replicas return conflict
2013+ errs := & replicationErrors {
2014+ threshold : 2 ,
2015+ }
2016+
2017+ // Add 1 unavailable error
2018+ errs .Add (errUnavailable )
2019+ // Add 2 conflict errors
2020+ errs .Add (storage .ErrOutOfOrderSample )
2021+ errs .Add (storage .ErrDuplicateSampleForTimestamp )
2022+
2023+ // Call Cause() to see what error is returned
2024+ cause := errs .Cause ()
2025+
2026+ // With threshold=2:
2027+ // - conflict count = 2 (>= threshold)
2028+ // - unavailable count = 1 (< threshold)
2029+ // Since conflict count meets the threshold, errConflict is returned
2030+ // This then gets mapped to HTTP 409 Conflict in the handler
2031+
2032+ require .Equal (t , errConflict , cause , "Expected errConflict since 2 conflicts meet the quorum threshold of 2" )
2033+ }
2034+
2035+ func TestWriteErrorsConflictScenario (t * testing.T ) {
2036+ t .Parallel ()
2037+
2038+ errs := & writeErrors {}
2039+
2040+ // Add 1 unavailable error
2041+ errs .Add (errUnavailable )
2042+ // Add 2 conflict errors
2043+ errs .Add (storage .ErrOutOfOrderSample )
2044+ errs .Add (storage .ErrDuplicateSampleForTimestamp )
2045+
2046+ // Call Cause() to see what error is returned
2047+ cause := errs .Cause ()
2048+
2049+ // writeErrors.Cause() now returns the most frequent error:
2050+ // - conflict count = 2
2051+ // - unavailable count = 1
2052+ // Since conflict is most frequent, errConflict is returned
2053+ // This maps to HTTP 409 Conflict
2054+
2055+ require .Equal (t , errConflict , cause , "Expected errConflict since it's the most frequent error (2 vs 1)" )
2056+ }
0 commit comments