pw_kvs: Fix relocation

Fix the vaild bytes accounting for the sector the entry is being
relocated out of.

Change-Id: Iec063aaa432691ee71e83993e88042e30143a932
diff --git a/pw_kvs/key_value_store.cc b/pw_kvs/key_value_store.cc
index 5663091..c9c4820 100644
--- a/pw_kvs/key_value_store.cc
+++ b/pw_kvs/key_value_store.cc
@@ -517,6 +517,8 @@
   };
   TempEntry* entry = reinterpret_cast<TempEntry*>(working_buffer_.data());
 
+  DBG("Relocating entry");  // TODO: add entry info to the log statement.
+
   // Read the entry to be relocated. Store the header in a local variable and
   // store the key and value in the TempEntry stored in the static allocated
   // working_buffer_.
@@ -541,7 +543,15 @@
   // Find a new sector for the entry and write it to the new location.
   SectorDescriptor* new_sector;
   TRY(FindSectorWithSpace(&new_sector, header.size(), &old_sector, true));
-  return AppendEntry(new_sector, &key_descriptor, key, as_bytes(value));
+  TRY(AppendEntry(new_sector, &key_descriptor, key, as_bytes(value)));
+
+  // Do the valid bytes accounting for the sector the entry was relocated out
+  // of.
+  // TODO: Move this accounting to a method in SectorDescriptor, with a
+  // safety/correctness check that valid_bytes >= size.
+  old_sector.valid_bytes -= header.size();
+
+  return Status::OK;
 }
 
 // Find either an existing sector with enough space that is not the sector to
diff --git a/pw_kvs/key_value_store_test.cc b/pw_kvs/key_value_store_test.cc
index c2848d7..fd4adf1 100644
--- a/pw_kvs/key_value_store_test.cc
+++ b/pw_kvs/key_value_store_test.cc
@@ -380,7 +380,7 @@
   }
 }
 
-TEST_F(KeyValueStoreTest, DISABLED_FuzzTest) {
+TEST_F(KeyValueStoreTest, FuzzTest) {
   if (test_partition.sector_size_bytes() < 4 * 1024 ||
       test_partition.sector_count() < 4) {
     PW_LOG_INFO("Sectors too small, skipping test.");