code: def test_update():
      subscriber = DummySubscriber()
  
      storage = InstanceStorage(
          cluster_id="test_cluster",
          storage=InMemoryStorage(),
          status_change_subscriber=subscriber,
      )
      instance1 = create_instance("instance1")
      instance2 = create_instance("instance2")
  
      assert (True, 1) == storage.upsert_instance(instance=instance1)
      assert subscriber.events == [
          InstanceUpdateEvent(
              instance_id="instance1",
              new_instance_status=Instance.UNKNOWN,
          ),
      ]
      assert (True, 2) == storage.upsert_instance(instance=instance2)
  
      assert subscriber.events == [
          InstanceUpdateEvent(
              instance_id="instance1",
              new_instance_status=Instance.UNKNOWN,
          ),
          InstanceUpdateEvent(
              instance_id="instance2",
              new_instance_status=Instance.UNKNOWN,
          ),
      ]
  
      assert (
          {
              "instance1": create_instance("instance1", version=1),
              "instance2": create_instance("instance2", version=2),
          },
          2,
      ) == storage.get_instances()
  
      # failed because instance version is not correct
      assert (False, 2) == storage.upsert_instance(
          instance=instance1,
          expected_instance_version=0,
      )
  
      # failed because storage version is not correct
      assert (False, 2) == storage.upsert_instance(
          instance=instance1,
          expected_storage_verison=0,
      )
  
      assert subscriber.events == [
          InstanceUpdateEvent(
              instance_id="instance1",
              new_instance_status=Instance.UNKNOWN,
          ),
          InstanceUpdateEvent(
              instance_id="instance2",
              new_instance_status=Instance.UNKNOWN,
          ),
      ]
  
      assert (True, 3) == storage.upsert_instance(
          instance=instance2,
          expected_storage_verison=2,
      )
  
      assert (
          {
              "instance1": create_instance("instance1", version=1),
              "instance2": create_instance("instance2", version=3),
          },
          3,
      ) == storage.get_instances()
  
      assert subscriber.events == [
          InstanceUpdateEvent(
              instance_id="instance1",
              new_instance_status=Instance.UNKNOWN,
          ),
          InstanceUpdateEvent(
              instance_id="instance2",
              new_instance_status=Instance.UNKNOWN,
          ),
          InstanceUpdateEvent(
              instance_id="instance2",
              new_instance_status=Instance.UNKNOWN,
          ),
      ]
  
      assert (True, 4) == storage.upsert_instance(
          instance=instance1,
          expected_instance_version=1,
      )
  
      assert (
          {
              "instance1": create_instance("instance1", version=4),
              "instance2": create_instance("instance2", version=3),
          },
          4,
      ) == storage.get_instances()
  
      assert subscriber.events == [
          InstanceUpdateEvent(
              instance_id="instance1",
              new_instance_status=Instance.UNKNOWN,
          ),
          InstanceUpdateEvent(
              instance_id="instance2",
              new_instance_status=Instance.UNKNOWN,
          ),
          InstanceUpdateEvent(
              instance_id="instance2",
              new_instance_status=Instance.UNKNOWN,
          ),
          InstanceUpdateEvent(
              instance_id="instance1",
              new_instance_status=Instance.UNKNOWN,
          ),
      ]
  
file_path: ray/python/ray/autoscaler/v2/tests/test_instance_storage.py
imports: import copy
  import os
  import sys
  from unittest import mock
  import pytest
  from ray.autoscaler.v2.instance_manager.instance_storage import InstanceStorage, InstanceUpdatedSubscriber, InstanceUpdateEvent
  from ray.autoscaler.v2.instance_manager.storage import InMemoryStorage
  from ray.core.generated.instance_manager_pb2 import Instance
label_desc: Use image node_id 3 for calling a global function with example usage: test_update() without return types