def test_fit_test_synchronization(tmp_path):
    """Test that the trainer synchronizes processes before returning control back to the caller."""
    model = TestDummyModelForCheckpoint()
    checkpoint = ModelCheckpoint(dirpath=tmp_path, monitor="x", mode="min", save_top_k=1)
    trainer = Trainer(
        default_root_dir=tmp_path,
        max_epochs=2,
        strategy="ddp_spawn",
        accelerator="cpu",
        devices=2,
        callbacks=[checkpoint],
    )
    trainer.fit(model)
    assert os.path.exists(checkpoint.best_model_path), f"Could not find checkpoint at rank {trainer.global_rank}"
    trainer.test()
Test that the trainer synchronizes processes before returning control back to the caller.
tests/tests_pytorch/trainer/test_trainer.py