[ledger_story_model_storage_unittest] Use 2 ledger for concurrent modifications

It is not legal to start 2 transactions in parallel on the same ledger
page. To prevent this, update the test to use 2 connections to the
ledger.

Change-Id: I6a5c79e143ed4c4a67125d92ea9442c26460e3a9
diff --git a/peridot/bin/sessionmgr/story/model/ledger_story_model_storage_unittest.cc b/peridot/bin/sessionmgr/story/model/ledger_story_model_storage_unittest.cc
index 5df4ff9..2205004 100644
--- a/peridot/bin/sessionmgr/story/model/ledger_story_model_storage_unittest.cc
+++ b/peridot/bin/sessionmgr/story/model/ledger_story_model_storage_unittest.cc
@@ -35,6 +35,8 @@
   LedgerStoryModelStorageTest() : executor(dispatcher()) {}
 
   // Creates a new LedgerStoryModelStorage instance and returns:
+  // If |ledger_client| is not specified the default client is used, otherwise
+  // use the given client.
   //
   // 1) A unique_ptr to the new instance.
   // 2) A ptr to a vector of lists of StoryModelMutations observed from that
@@ -42,9 +44,16 @@
   // 3) A ptr to a StoryModel updated with the observed commands.
   std::tuple<std::unique_ptr<StoryModelStorage>,
              std::vector<std::vector<StoryModelMutation>>*, StoryModel*>
-  Create(std::string page_id, std::string device_id) {
+  Create(std::string page_id, std::string device_id,
+         LedgerClient* ledger_client = nullptr) {
+
+    // If not client is specified, use the default client.
+    if (!ledger_client) {
+      ledger_client = this->ledger_client();
+    }
+
     auto storage = std::make_unique<LedgerStoryModelStorage>(
-        ledger_client(), MakePageId(page_id), device_id);
+        ledger_client, MakePageId(page_id), device_id);
 
     auto observed_commands =
         observed_mutations_.emplace(observed_mutations_.end());
@@ -127,8 +136,9 @@
 TEST_F(LedgerStoryModelStorageTest, DeviceLocal_DeviceIsolation) {
   auto [storage1, observed_mutations1, observed_model1] =
       Create("page1", "device1");
+  auto second_ledger_connection = NewLedgerClient();
   auto [storage2, observed_mutations2, observed_model2] =
-      Create("page1", "device2");
+      Create("page1", "device2", second_ledger_connection.get());
 
   // Set runtime state to RUNNING on device1, and set visibility state to
   // IMMERSIVE on device2.
diff --git a/peridot/lib/testing/test_with_ledger.cc b/peridot/lib/testing/test_with_ledger.cc
index 4676982..5e125c464 100644
--- a/peridot/lib/testing/test_with_ledger.cc
+++ b/peridot/lib/testing/test_with_ledger.cc
@@ -15,9 +15,7 @@
 TestWithLedger::TestWithLedger() {
   ledger_app_ = std::make_unique<testing::LedgerRepositoryForTesting>();
 
-  ledger_client_ = std::make_unique<LedgerClient>(
-      ledger_app_->ledger_repository(), __FILE__,
-      [](zx_status_t status) { ASSERT_TRUE(false) << "Status: " << status; });
+  ledger_client_ = NewLedgerClient();
 };
 
 TestWithLedger::~TestWithLedger() {
@@ -32,6 +30,12 @@
   ledger_app_.reset();
 };
 
+std::unique_ptr<LedgerClient> TestWithLedger::NewLedgerClient() {
+  return std::make_unique<LedgerClient>(
+      ledger_app_->ledger_repository(), __FILE__,
+      [](zx_status_t status) { ASSERT_TRUE(false) << "Status: " << status; });
+}
+
 bool TestWithLedger::RunLoopWithTimeout(zx::duration timeout) {
   return RealLoopFixture::RunLoopWithTimeout(timeout);
 }
diff --git a/peridot/lib/testing/test_with_ledger.h b/peridot/lib/testing/test_with_ledger.h
index b2b9eb2..426ad7b 100644
--- a/peridot/lib/testing/test_with_ledger.h
+++ b/peridot/lib/testing/test_with_ledger.h
@@ -23,6 +23,8 @@
 //
 // The ledger client is available to the test case and its fixture through the
 // ledger_client() getter, the ledger repository through ledger_repository().
+// If multiple connection to the same ledger is necessary, and new connection
+// can be created with |NewLedgerClient|.
 class TestWithLedger : public gtest::RealLoopFixture {
  public:
   TestWithLedger();
@@ -34,6 +36,10 @@
   }
   LedgerClient* ledger_client() { return ledger_client_.get(); }
 
+  // Build a new LedgerClient connecting to the same underlying ledger.
+  // This class must outlive the resulting client.
+  std::unique_ptr<LedgerClient> NewLedgerClient();
+
   // Increases default timeout over plain test with message loop, because
   // methods executing on the message loop are real fidl calls.
   //