code: def test_keep_most_recently_published(self):
      policy = garbage_collection_policy_pb2.GarbageCollectionPolicy(
          keep_most_recently_published=garbage_collection_policy_pb2.GarbageCollectionPolicy.KeepMostRecentlyPublished(
              num_artifacts=1
          )
      )
      self._example_gen.outputs.outputs[
          "examples"
      ].garbage_collection_policy.CopyFrom(policy)
      example_gen_node_uid = task_lib.NodeUid.from_node(
          self._pipeline, self._example_gen
      )
      pipeline_ops.initiate_pipeline_start(
          self._metadata, self._pipeline
      )
      example_gen_execution = (
          test_utils.fake_example_gen_run_with_handle(
              self._metadata, self._example_gen, span=0, version=0
          )
      )
      example_gen_output = self._metadata.get_outputs_of_execution(
          example_gen_execution.id
      )
      examples = example_gen_output["examples"]
      # No examples should be garbage collected.
      self.assertArtifactIdsEqual(
          [],
          garbage_collection.get_artifacts_to_garbage_collect_for_node(
              self._metadata, example_gen_node_uid, self._example_gen
          ),
      )
  
      # Sleep to ensure the second span has a later publish time than the first.
      # The artifact's create_time_since_epoch is set by ML Metadata, and this
      # test uses the ML Metadata C++ Sqlite implementation, so we can't use
      # unittest.mock.patch to change the artifact's create_time_since_epoch.
      time.sleep(1)
      test_utils.fake_example_gen_run_with_handle(
          self._metadata, self._example_gen, span=1, version=0
      )
      # The newest examples should be kept, and the oldest examples should be
      # garbage collected.
      self.assertArtifactIdsEqual(
          examples,
          garbage_collection.get_artifacts_to_garbage_collect_for_node(
              self._metadata, example_gen_node_uid, self._example_gen
          ),
      )
  
imports: import os
  import time
  from typing import Iterable, Optional, Union
  from absl import logging
  from absl.testing import parameterized
  from absl.testing.absltest import mock
  import tensorflow
  from tfx.dsl.io import fileio
  from tfx.orchestration import metadata
  from tfx.orchestration.experimental.core import garbage_collection
  from tfx.orchestration.experimental.core import pipeline_ops
  from tfx.orchestration.experimental.core import task
  from tfx.orchestration.experimental.core import test_utils
  from tfx.orchestration.experimental.core.testing import test_async_pipeline
  from tfx.proto.orchestration import garbage_collection_policy_pb2
  from tfx.types.artifact import Artifact
  from ml_metadata.proto import metadata_store_pb2
label_desc: Use image node_id 9 for calling the GarbageCollectionTest obj's underlying member method code with example usage: obj.test_keep_most_recently_published() without return types