Repository: risingwavelabs/risingwave
File: src/meta/src/rpc/ddl_controller.rs (Rust)

Code before:
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(256).unwrap(),
            Some(NonZeroUsize::new(4).unwrap()),
            &DefaultParallelism::Default(NonZeroUsize::new(50).unwrap()),
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 50);
    }

    #[test]
    fn full_parallelism_respects_max_parallelism_cap() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(6).unwrap(),
            Some(NonZeroUsize::new(10).unwrap()),
            &DefaultParallelism::Full,
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 6);
    }

    #[test]
    fn zero_available_returns_unavailable_error() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(4).unwrap(),
            None,
            &DefaultParallelism::Full,
            "default",
        );
        assert!(matches!(
            result,
            Err(ref e) if matches!(e.inner(), MetaErrorInner::Unavailable(_))
        ));
    }

    #[test]
    fn specified_over_max_is_rejected() {
        let result = DdlController::resolve_stream_parallelism_inner(
            Some(NonZeroUsize::new(8).unwrap()),
            NonZeroUsize::new(4).unwrap(),
            Some(NonZeroUsize::new(10).unwrap()),
            &DefaultParallelism::Full,
            "default",
        );
        assert!(matches!(
            result,
            Err(ref e) if matches!(e.inner(), MetaErrorInner::InvalidParameter(_))

Review comment (suggestion):
[nitpick] Test name `zero_available_returns_unavailable_error` could be clearer. Consider renaming to `test_no_available_slots_returns_error` to better communicate that `None` (no available slots) triggers an error, and follow common test naming conventions (starting with `test_`).
```suggestion
    fn test_no_available_slots_returns_error() {
```

Code after:
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(256).unwrap(),
            Some(NonZeroUsize::new(4).unwrap()),
            &DefaultParallelism::Default(NonZeroUsize::new(50).unwrap()),
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 50);
    }

    #[test]
    fn test_full_parallelism_capped_by_max() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(6).unwrap(),
            Some(NonZeroUsize::new(10).unwrap()),
            &DefaultParallelism::Full,
            "default",
        )
        .unwrap();
        assert_eq!(result.get(), 6);
    }

    #[test]
    fn test_no_available_slots_returns_error() {
        let result = DdlController::resolve_stream_parallelism_inner(
            None,
            NonZeroUsize::new(4).unwrap(),
            None,
            &DefaultParallelism::Full,
            "default",
        );
        assert!(matches!(
            result,
            Err(ref e) if matches!(e.inner(), MetaErrorInner::Unavailable(_))
        ));
    }

    #[test]
    fn test_specified_over_max_returns_error() {
        let result = DdlController::resolve_stream_parallelism_inner(
            Some(NonZeroUsize::new(8).unwrap()),
            NonZeroUsize::new(4).unwrap(),
            Some(NonZeroUsize::new(10).unwrap()),
            &DefaultParallelism::Full,
            "default",
        );
        assert!(matches!(
            result,
            Err(ref e) if matches!(e.inner(), MetaErrorInner::InvalidParameter(_))