diff --git a/posts_create.go b/posts_create.go index 7c9001b..fc389f1 100644 --- a/posts_create.go +++ b/posts_create.go @@ -138,6 +138,14 @@ func (c *Client) CreateCarouselPost(ctx context.Context, content *CarouselPostCo return nil, err } + // Wait for all child containers to be ready before creating the carousel container + // The Threads API requires child containers to be in FINISHED status + for i, childID := range content.Children { + if err := c.waitForContainerReady(ctx, ContainerID(childID), DefaultContainerPollMaxAttempts, DefaultContainerPollInterval); err != nil { + return nil, fmt.Errorf("child container %d (%s) not ready: %w", i+1, childID, err) + } + } + // Create container first containerID, err := c.createCarouselContainer(ctx, content) if err != nil { diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 872d008..a079671 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -341,8 +341,7 @@ func TestIntegration_PostOperations(t *testing.T) { } t.Logf("Created second media container: %s", container2) - // Wait a moment for containers to be ready - time.Sleep(1 * time.Second) + // Note: No sleep needed - CreateCarouselPost waits for child containers to be ready // Create carousel post content := &threads.CarouselPostContent{ @@ -681,7 +680,7 @@ func TestIntegration_SpoilersAndTextAttachments(t *testing.T) { return } - time.Sleep(1 * time.Second) + // Note: No sleep needed - CreateCarouselPost waits for child containers to be ready // Create carousel with all media marked as spoilers content := &threads.CarouselPostContent{