impress-2020/src/server/outfit-images.test.js

54 lines
1.8 KiB
JavaScript
Raw Normal View History

import { renderOutfitImage } from "./outfit-images";
import { toMatchImageSnapshot } from "jest-image-snapshot";
expect.extend({ toMatchImageSnapshot });
const originalConsoleWarn = console.warn;
describe("renderOutfitImage", () => {
beforeEach(() => {
console.warn = jest.fn();
});
afterEach(() => {
console.warn = originalConsoleWarn;
});
it("renders the Moon and Stars Background and Green Leaf String Lights, as PNG", async () => {
const image = await renderOutfitImage(
[
Use Fastly to cache our PNG assets from S3 We've been serving images directly from `impress-asset-images.s3.amazonaws.com` for a long time. While they serve with long-lasting HTTP cache headers, and the app requests them with the `updated_at` timestamp in the query string; each GET request still executes a full S3 ReadObject operation to get the latest version. In the past, this was only relevant to users on Image Mode, not Flash Mode. But now that everyone's on Image Mode, this matters a lot more! Now, we've configured a Fastly host at `impress-asset-images.openneo.net`, to sit in front of our S3 bucket. This should dramatically reduce the GET requests to S3 itself, as our cache warms up and gains copies of the most common asset PNGs. That said, I'm not sure how much actual cost impact this change will have. Our AWS console isn't configured to differentiate cost by bucket yet—I've started this process, but it might take a few days to propagate. All I know is that our current costs are $35/mo data transfer + $20/mo storage, and that outfit images are responsible for most of the storage cost. I hypothesize that `impress-asset-images` is responsible for most of the reads and data transfers, but I'm not sure! In the future, I think we'll be able to bring our AWS costs to near-zero, by: - Obsolete `impress-asset-images`, by using the official Neopets PNGs instead, after the HTML5 conversion completes. - Obsolete `impress-outfit-images`, by using a Node endpoint to generate the images, fronted by a CDN cache. (Transfer the actual data to a long-term storage backup, and replace the S3 objects with redirects, so that old S3 URLs will still work.) I hope this will be a big slice of the costs though! 🤞 (Note: I'll be deploying this on a bit of a delay, because I want to see the DNS propagate across the globe before flipping to a new domain!)
2021-05-12 22:48:46 -07:00
"https://impress-asset-images.openneo.net/object/000/000/006/6829/600x600.png",
"https://impress-asset-images.openneo.net/object/000/000/036/36414/600x600.png",
],
600
);
expect(image).toMatchImageSnapshot();
expect(console.warn).not.toHaveBeenCalled();
});
it("renders the Moon and Stars Background and Green Leaf String Lights, as SVG", async () => {
const image = await renderOutfitImage(
[
"http://images.neopets.com/cp/items/data/000/000/006/6829_1707e50385/6829.svg",
"http://images.neopets.com/cp/items/data/000/000/036/36414_1e2aaab4ad/36414.svg",
],
600
);
expect(image).toMatchImageSnapshot();
expect(console.warn).not.toHaveBeenCalled();
});
it("skips network failures, and logs an error", async () => {
const image = await renderOutfitImage(
[
Use Fastly to cache our PNG assets from S3 We've been serving images directly from `impress-asset-images.s3.amazonaws.com` for a long time. While they serve with long-lasting HTTP cache headers, and the app requests them with the `updated_at` timestamp in the query string; each GET request still executes a full S3 ReadObject operation to get the latest version. In the past, this was only relevant to users on Image Mode, not Flash Mode. But now that everyone's on Image Mode, this matters a lot more! Now, we've configured a Fastly host at `impress-asset-images.openneo.net`, to sit in front of our S3 bucket. This should dramatically reduce the GET requests to S3 itself, as our cache warms up and gains copies of the most common asset PNGs. That said, I'm not sure how much actual cost impact this change will have. Our AWS console isn't configured to differentiate cost by bucket yet—I've started this process, but it might take a few days to propagate. All I know is that our current costs are $35/mo data transfer + $20/mo storage, and that outfit images are responsible for most of the storage cost. I hypothesize that `impress-asset-images` is responsible for most of the reads and data transfers, but I'm not sure! In the future, I think we'll be able to bring our AWS costs to near-zero, by: - Obsolete `impress-asset-images`, by using the official Neopets PNGs instead, after the HTML5 conversion completes. - Obsolete `impress-outfit-images`, by using a Node endpoint to generate the images, fronted by a CDN cache. (Transfer the actual data to a long-term storage backup, and replace the S3 objects with redirects, so that old S3 URLs will still work.) I hope this will be a big slice of the costs though! 🤞 (Note: I'll be deploying this on a bit of a delay, because I want to see the DNS propagate across the globe before flipping to a new domain!)
2021-05-12 22:48:46 -07:00
"https://impress-asset-images.openneo.net/object/000/000/006/6829/600x600.png",
"https://impress-asset-images.openneo.net/object/000/000/000/00000000/600x600.png", // fake URL
],
600
);
expect(image).toMatchImageSnapshot();
expect(console.warn).toHaveBeenCalledWith(
Use Fastly to cache our PNG assets from S3 We've been serving images directly from `impress-asset-images.s3.amazonaws.com` for a long time. While they serve with long-lasting HTTP cache headers, and the app requests them with the `updated_at` timestamp in the query string; each GET request still executes a full S3 ReadObject operation to get the latest version. In the past, this was only relevant to users on Image Mode, not Flash Mode. But now that everyone's on Image Mode, this matters a lot more! Now, we've configured a Fastly host at `impress-asset-images.openneo.net`, to sit in front of our S3 bucket. This should dramatically reduce the GET requests to S3 itself, as our cache warms up and gains copies of the most common asset PNGs. That said, I'm not sure how much actual cost impact this change will have. Our AWS console isn't configured to differentiate cost by bucket yet—I've started this process, but it might take a few days to propagate. All I know is that our current costs are $35/mo data transfer + $20/mo storage, and that outfit images are responsible for most of the storage cost. I hypothesize that `impress-asset-images` is responsible for most of the reads and data transfers, but I'm not sure! In the future, I think we'll be able to bring our AWS costs to near-zero, by: - Obsolete `impress-asset-images`, by using the official Neopets PNGs instead, after the HTML5 conversion completes. - Obsolete `impress-outfit-images`, by using a Node endpoint to generate the images, fronted by a CDN cache. (Transfer the actual data to a long-term storage backup, and replace the S3 objects with redirects, so that old S3 URLs will still work.) I hope this will be a big slice of the costs though! 🤞 (Note: I'll be deploying this on a bit of a delay, because I want to see the DNS propagate across the globe before flipping to a new domain!)
2021-05-12 22:48:46 -07:00
`Error loading layer, skipping: Server responded with 403. (https://impress-asset-images.openneo.net/object/000/000/000/00000000/600x600.png)`
);
});
});